-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
Because the static request methods on the Http class are implemented by creating a Request instance and setting the uri and headers fields, there is an issue where the content-type header cannot be defined because the Request class is assumed to be of content-type text/plain. In other words, the following does not work as one would expect:
final uri = ...;
Http.post(uri, headers: {'content-type': 'application/json'});
// Should send a request with content-type: application/json
// but actually sends a request with content-type: text/plainThe workaround is to construct the appropriate request class instance and modify the content-type via the contentType field:
// Some content-types like application/json are handled by classes
// provided by w_transport:
final jsonRequest = new JsonRequest();
jsonRequest.post(); // will be sent with content-type: application/json
// If there isn't a class that supports your desired content-type,
// you can construct a regular `Request` and set it manually:
final xmlRequest = new Request()
..contentType = new MediaType('application', 'xml');
xmlRequest.post(); // will be sent with content-type: application/xmlReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels