1

I don't manage to read response headers using browser_client.dart :

import 'package:http/browser_client.dart';


var response =
await client.post(url, headers: {
  'Content-Type': 'application/json',
  'Accept': 'application/json'
}, body: body);
print('Response headers: ${response.headers}');

Thanks for your help.

matth3o
  • 3,229
  • 3
  • 20
  • 24
  • 1
    This works for me. Perhaps the server doesn't send the headers or they are suppressed by the browser because of CORS issues? (`Access-control-allow-headers`, `Access-control-expose-headers`)? – Günter Zöchbauer Sep 05 '16 at 15:42
  • 1
    Thanks, `Access-control-expose-headers` was missing... It works now! – matth3o Sep 05 '16 at 15:49

1 Answers1

2

The server needs to allow the browser to expose the headers by listing the headers in the Access-control-expose-headers response header, otherwise you can see them in the browser devtools but when you try to read them in code, the browser will suppress them.

See also

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567