0

I am using http post to send some information and get back the response.

final response = await http.post(
                      Uri.parse(
                        "some url"
                      ),
                      headers: <String, String>{
                        'email': email,
                        'callbacktoken': callbacktoken
                      },
                    );

When I run this, my execution gets stuck at this codeblock ( I tried putting a print statement in the next line) when the response coming from the backend has header values, however if I send the response with no header from the backend (I am using django at the backend) then the my program runs with no issue.

So my question is how to handle responses with headers and how to extract them?

Sid
  • 378
  • 1
  • 13
  • "if I send the response" - you mean "send the request"? if so, you need to send a request with some custom headers and then read [headers](https://pub.dev/documentation/http/latest/http/BaseResponse/headers.html) from the response? – pskink Jun 10 '21 at 14:27
  • @pskink No I mean when my django backend sends the response with header values – Sid Jun 10 '21 at 14:29
  • what does [network view](https://flutter.dev/docs/development/tools/devtools/network) show? – pskink Jun 10 '21 at 14:33
  • @pskink status is blank and duration is pending even 2 min after request – Sid Jun 10 '21 at 14:37
  • Can you change `` to `Map` ? I already had some issues when I don't force exactly the type... You might give it a chance ! – BabC Jun 10 '21 at 14:58
  • @BabC I dont think thats the problem cuz i do receive the data in my backend it is the response that is not being handled at the frontend side – Sid Jun 10 '21 at 16:07
  • @pskink return Response(data='New user detected', headers={'token': '', 'New user': 'true'}, status=200) everything before this is working I have checked. – Sid Jun 10 '21 at 16:09
  • @pskink Actually the problem was in my backend I was not following the convention and had white space in my header name that was the problem – Sid Jun 10 '21 at 16:40

1 Answers1

0

After a little researching I finally found the issue. My custom header name had space in it "New user" because of which http was not able to parse it. After changing the name to "newuser" everything is working fine.

Sid
  • 378
  • 1
  • 13