1

With package https://pub.dev/packages/http I can send post request with await http.post() and get http.Response which have Map parameter headers.

Problem is that that header variable returns only part of response headers like {cache-control: private, content-length: 1159, content-type: text/csv} but request is always having more than that enter image description here but it isn't shown in flutter

Request is not multipart, but classic post request with version http: ^0.13.3

[✓] Flutter (Channel stable, 2.5.1, on Manjaro Linux 5.12.19-1-MANJARO, locale en_US.UTF-8)
    • Flutter version 2.5.1 at ---
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ffb2ecea52 (6 days ago), 2021-09-17 15:26:33 -0400
    • Engine revision b3af521a05
    • Dart version 2.14.2

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at ---
    • Platform android-30, build-tools 30.0.3
    • Java binary at: ---
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • CHROME_EXECUTABLE = ---

[✓] Android Studio (version 4.1)
    • Android Studio at ---
    • 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-b3-6222593)

[✓] Connected device (1 available)
    • Chrome (web) • chrome • web-javascript • Chromium 93.0.4577.82 snap

• No issues found!
  • 1
    Just ran the most basic test where I http.post-ed to my own server and successfully for the content-disposition header back. Feel free to share a minimal reproducible example for us to take a look. – jabbson Sep 24 '21 at 15:03
  • Also verify the same request with the curl command to see if the header actually is there. – jabbson Sep 24 '21 at 15:10
  • @jabbson Did you run it on Firefox. It ends up happening only on firefox (latest version and every version I tried). I am also having CORS issue with firefox https://github.com/flutter/flutter/issues/90484 and Firefox is one of the most important browsers for my users. – Veljko Djuricic Sep 24 '21 at 19:34
  • Hold on, what Firefox?.. I though you meant your client was an http client within your code?.. – jabbson Sep 24 '21 at 19:55
  • No, http client is used in flutter and headers can be seen in Firefox network developer page but when I print and try to get headers of post request in flutter, I only get this three {cache-control: private, content-length: 1159, content-type: text/csv}. In chrome I can get all headers, but on Firefox flutter can get only this three – Veljko Djuricic Sep 24 '21 at 21:48
  • You have soluton for this? – John Joe Nov 10 '21 at 06:20

2 Answers2

0

I am relatively sure the issue is related to the browser not allowing to access the headers from a different origin unless the back-end allows this.

Add "Access-Control-Expose-Headers" header to the response and see if this helps. Read more here.

jabbson
  • 4,390
  • 1
  • 13
  • 23
0

Not sure if it is your case but I upload binary data to my server like this

 final uploadResponse = await http.put(
          Uri.parse(fileUploadUrl),
          headers: {
            HttpHeaders.contentTypeHeader: ContentType.binary.toString(),
            'Content-Disposition':
                'Content-Disposition: attachment; filename=$fileName'
          },
          body: file.readAsBytesSync(),
        );
sultanmyrza
  • 4,551
  • 1
  • 30
  • 24