Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using HTTP client to send requests, it is found that request HTTP header is all lowercase. #16665

Closed
fly512 opened this issue Apr 17, 2018 · 18 comments

Comments

@fly512
Copy link

fly512 commented Apr 17, 2018

Using HTTP client to send requests, it is found that request HTTP header is all lowercase.
Such a part of the server will reject my request
How to correct the repair

@jonahwilliams
Copy link
Member

jonahwilliams commented Apr 17, 2018

@fly512 Which HttpClient are you using - dart:io or package:http?

@jonahwilliams
Copy link
Member

Also field headers are case insensitive, per my understanding of http

@zoechi
Copy link
Contributor

zoechi commented Apr 17, 2018

Looks like a dup of dart-lang/sdk#25120

@fly512
Copy link
Author

fly512 commented Apr 18, 2018

@zoechi
Copy link
Contributor

zoechi commented Apr 18, 2018

@fly512 it's intentional. The server you are using is not HTTP compliant.

@fly512
Copy link
Author

fly512 commented Apr 18, 2018

@zoechi I think so, but we can't control the header sent by HTTP, which sounds strange. Or do I need to use socket to handle it on my own? But it may take a long time, and it may not be reliable.

@zoechi
Copy link
Contributor

zoechi commented Apr 18, 2018

You are not supposed to influence casing of headers because according to the standard it needs to be ignored.

@boapps
Copy link

boapps commented Jul 16, 2018

I also have the same problem and I tried contacting the support, but they didn't want change the headers, so now I have to make it work somehow. Can I modify Flutter source files so the headers are case-sensitive, or write a plugin for that, or create a plugin that uses the native (Java/Swift) HTTP requests, because I know that Android's HttpsURLConnection uses case-sensitive headers, not sure about Swift though.

@zoechi
Copy link
Contributor

zoechi commented Jul 16, 2018

@boapps They shouldn't need to change their headers.
They should change their code to accept headers independent of casing according to the HTTP standard.

Sure, you can create a Flutter plugin that uses native Android or iOS implementations.
There is no way to change the Flutter source. This functionality is part of the Dart SDK.

@boapps
Copy link

boapps commented Jul 16, 2018

@zoechi Thanks for the reply sorry for bad wording, I contacted them and I actually asked them to make their headers case-sensitive and told them that their API is not HTTP compliant, nothing changed and got a template response (to be fair, I am creating an unofficial client app for the official Hungarian-school-evaluation-management-system thing and their API was not documented anywhere, I discovered it with wireshark).
I will try implementing native HTTP requests with a plugin then, I might also open-source it and maybe share progress here, thanks for the help!

@zoechi
Copy link
Contributor

zoechi commented Aug 28, 2018

I'm going to close this because I there is nothing the Flutter team can do.

@zoechi zoechi closed this as completed Aug 28, 2018
@catalin260
Copy link

@zoechi Thanks for the reply sorry for bad wording, I contacted them and I actually asked them to make their headers case-sensitive and told them that their API is not HTTP compliant, nothing changed and got a template response (to be fair, I am creating an unofficial client app for the official Hungarian-school-evaluation-management-system thing and their API was not documented anywhere, I discovered it with wireshark).
I will try implementing native HTTP requests with a plugin then, I might also open-source it and maybe share progress here, thanks for the help!

Hello @boapps ,

Did you find a solution for this problem? I'm in the same problem as you described here.

@boapps
Copy link

boapps commented Jun 8, 2019

@catalin260 I wrote a plugin that could do simple http push and get requests. Nothing special, it just passes some headers and a URL to the Android HttpURLConnection then returns the result text. It only works for Android. But I don't use it, because I found a workaround the initial problem.

@gsy13213009
Copy link

What? the bug is closed? So what can we do to keep the header?

@ghost
Copy link

ghost commented Aug 24, 2019

@boapps whats is the workaround?

@cdm2012
Copy link

cdm2012 commented Dec 29, 2019

Creating an API Client using HTTPClient with the following request headers:

I/flutter (32611): headers: {
I/flutter (32611):   "Content-type": "application/json",
I/flutter (32611):   "Accept": "application/json",
I/flutter (32611):   "Authorization": "Bearer: E7HlYmfiXwhLQT1nYApOAE4wqhvCZZXndrT7kiRv8tUBycj3npVnYwnQnH34"
I/flutter (32611): }
I/flutter (32611): 
I/flutter (32611): 
I/flutter (32611): 
I/flutter (32611): request.headers: 
I/flutter (32611): content-type: application/json
I/flutter (32611): accept: application/json
I/flutter (32611): authorization: Bearer: E7HlYmfiXwhLQT1nYApOAE4wqhvCZZXndrT7kiRv8tUBycj3npVnYwnQnH34

And the server (nginx/1.15.8) is returning a 400 error:

I/flutter (32611): <html>
I/flutter (32611): <head><title>400 Bad Request</title></head>
I/flutter (32611): <body>
I/flutter (32611): <center><h1>400 Bad Request</h1></center>
I/flutter (32611): <hr><center>nginx/1.15.8</center>
I/flutter (32611): </body>
I/flutter (32611): </html>

Using the same headers in android with the following request headers:

E: Called doInBackground w/ headers: [Accept: application/json, Content-type: application/json, Authorization: Bearer E7HlYmfiXwhLQT1nYApOAE4wqhvCZZXndrT7kiRv8tUBycj3npVnYwnQnH34]

And the same server is returning a 200 response, so I'm really looking forward to integrating the change by @zichangg : dart-lang/sdk#39657 (comment)

See Dart Issue Comment on the same issue here dart-lang/sdk#33501 (comment)

@MiriDevAndro
Copy link

do you have find an solution ?

@lock
Copy link

lock bot commented Apr 2, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@lock lock bot locked and limited conversation to collaborators Apr 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants