Reputation: 852
I am making a simple flutter app using http package.
I am trying to send a (post) login request, and the httpresponse is missing all the headers!
this works fine in ios simulator but in chrome as you can see there are only 2 headers available;
What is wrong? Thanks
Upvotes: 2
Views: 590
Reputation: 891
Setting the header param "Access-Control-Expose-Headers" = "*"
from the server side did the trick.
Please see the issue detail here: https://github.com/dart-lang/http/issues/726#issuecomment-1433169316
Upvotes: 1
Reputation: 1
I have the following:
Response headers web:
"Origin":"http://localhost:57986"
Example code:
Future<File> downloadFile(String url, String pathFile) async {
File file = new File(pathFile);
var request = await http.post(Uri.parse(url), encoding: Encoding.getByName('utf8'), headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST, GET, OPTIONS, PUT, DELETE, HEAD",
});
if (request.statusCode == 200) {
Map<String, String> headers = request.headers;
if (headers.containsKey("Origin")) {
var origin = headers['Origin'];
print("your result: " + origin.toString());
}
file.writeAsBytes(request.bodyBytes);
}
return file;
}
Upvotes: 0