2

I try to get the cookie from an HTTP request in flutter web but It just back Content-type and cache-control. I checked my request with curl and it had Set-cookie in the response.

Flutter code:

final response = await http.post(
      Uri.parse(Api.BASE_URL),
      headers: <String, String>{
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
      },
      body: {
        'parameter1': Api.TOKEN,
        'parameter2': SOME_PARAMETERS
      },
    );
    response.headers.forEach((k, v) => debugPrint('$k: $v'));

debug print

cache-control: no-cache
content-type: application/json;charset=UTF-8

curl command:

curl -X HEAD -i MY_API_ADDRESS --insecure

curl result:

Cache-Control: private
Expires: SOME_DATE
Set-Cookie: SOME_COOKIE
Access-Control-Allow-Origin: *
Access-Control-Request-Method: *
Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token
Transfer-Encoding: deflate
Cache-Control: no-cache
Connection: keep-alive
X-Frame-Options: sameorigin
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Wed, 24 Nov 2021 12:37:00 GMT
Saman
  • 2,506
  • 4
  • 22
  • 41
  • Oh, it's a web client. Is the client running on a different domain than the API itself? In other words, is it a CORS request? – Boaz Nov 24 '21 at 13:34
  • Yes, I did not mention it. But I was set `Access-Control-Expose-Headers` on the server-side. – Saman Nov 24 '21 at 13:37
  • Okay :) So this i probably the correct duplicate: [Dart BrowserClient POST not including my cookie](https://stackoverflow.com/questions/29427203/dart-browserclient-post-not-including-my-cookies) – Boaz Nov 24 '21 at 13:58

0 Answers0