I am using MultipartRequest in dart in order to upload files to API. However I need to add an authorization header to my request. The problem that i am facing is that the header attribute is final and I can't overwrite it. How can I fix that? Thank you!
headers
is a Map
, so add the key/value.
http.MultipartRequest request =
new http.MultipartRequest('POST', Uri.parse(url));
request.headers['authorization'] = 'the auth header value';
Alternatively, if you want to pass all the preconfigured header (key, value) Map, from your, let's say _headers
, you can do something like:
_headers.forEach((k, v) {
request.headers[k] = v;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With