dart-lang / http

A composable API for making HTTP requests in Dart.
https://pub.dev/packages/http
BSD 3-Clause "New" or "Revised" License
1.02k stars 353 forks source link

HTTP request failed, statusCode: 504 but works fine on Browser!! #733

Open bismarabia opened 2 years ago

bismarabia commented 2 years ago

I have the following image

https://www.gardeningknowhow.com/wp-content/uploads/2012/10/date-palm.jpg

It works fine on browser

image

but not using this lib

get(Uri.parse("https://www.gardeningknowhow.com/wp-content/uploads/2012/10/date-palm.jpg")).then((Response value) {
      print("request -> ${value.request}");
      print("statusCode -> ${value.statusCode}");
      print("reasonPhrase -> ${value.reasonPhrase}");
      print("contentLength -> ${value.contentLength}");
      print("headers -> ${value.headers}");
      print("isRedirect -> ${value.isRedirect}");
      print("persistentConnection -> ${value.persistentConnection}");
    });

and gives the following error:

flutter: request -> GET https://www.gardeningknowhow.com/wp-content/uploads/2012/10/date-palm.jpg
flutter: statusCode -> 504
flutter: reasonPhrase -> Gateway Timeout
flutter: contentLength -> 0
flutter: headers -> {connection: keep-alive, x-hw: 1657788860.cds204.ma1.hn,1657788860.cds204.ma1.h2c, cache-control: max-age=10, date: Thu, 14 Jul 2022 08:54:20 GMT, accept-ranges: bytes, content-length: 0}
flutter: isRedirect -> false
flutter: persistentConnection -> true

when I tried in Postman, here is the full raw log:

GET /wp-content/uploads/2012/10/date-palm.jpg HTTP/1.1
User-Agent: PostmanRuntime/7.29.0
Accept: */*
Postman-Token: c1a4f125-aa55-4076-b8f0-1c96b2baa22f
Host: www.gardeningknowhow.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive

HTTP/1.1 200 OK
Date: Thu, 14 Jul 2022 09:24:20 GMT
Content-Type: image/jpeg
Last-Modified: Mon, 29 Mar 2021 01:24:39 GMT
Accept-Ranges: bytes
CF-Ray: 7242195b8af232ac-CDG
Access-Control-Allow-Origin: *
Cache-Control: max-age=315360000
ETag: "60612c57-95f75"
CF-Cache-Status: DYNAMIC
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
ki-cache-type: None
Ki-CF-Cache-Status: BYPASS
ki-edge: v=17.6
X-Content-Type-Options: nosniff
X-Edge-Location-Klb: 1
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=VdU8kWcY3vDd6AIvKuLSmvEEUwaGa8skQj4LQlLiJbv2PhNrBmmYw5mdexDwiOApUhrNJPMVAsUU66OQg5lTHwbowSylSRSXERSnG7IE17nJZiW7maM85QVQFiISlGAp8qLrH7WNXU6AWQ%3D%3D"}],"group":"cf-nel","max_age":604800}
NEL: {"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}
Alt-Svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400
Server: fbs
Vary: Accept-Encoding
X-HW: 1657790660.cds217.ma1.hn,1657790660.cds040.ma1.c
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 614261

Here is my flutter doctor output

[√] Flutter (Channel beta, 3.1.0-9.0.pre, on Microsoft Windows [Version 10.0.19044.1706], locale en-US)
    • Flutter version 3.1.0-9.0.pre at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f28e570c8c (11 days ago), 2022-06-14 13:39:33 -0500
    • Engine revision 74ee6b5afd
    • Dart version 2.18.0 (build 2.18.0-165.1.beta)
    • DevTools version 2.14.0

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at C:\Users\dsfs\AppData\Local\Android\sdk
    • Platform android-30, build-tools 29.0.3
    • Java binary at: C:\Program Files\Android\android-studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.2.1)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.2.32516.85
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 3.5)
    • Android Studio at D:\Softwares\android-studio
    • Flutter plugin version 34.0.2
    • Dart plugin version 183.5901
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[√] Android Studio (version 4.1)
    • Android Studio at C:\Users\dsfs\OneDrive\Documents\EGDownloads\Compressed\android-studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] Android Studio (version 4.2)
    • Android Studio at C:\Program Files\Android\android-studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)

[√] IntelliJ IDEA Ultimate Edition (version 2018.2)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2018.2.2
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart

[√] VS Code (version 1.54.1)
    • VS Code at C:\Users\dsfs\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension can be installed from:
       https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19044.1706]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 102.0.5005.115
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 103.0.1264.37

[√] HTTP Host Availability
    • All required HTTP hosts are available

Any idea how to overcome or fix this?

mojtabana commented 1 year ago

try dart dev tools to intercept actual GET