You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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/plain
The 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 =newJsonRequest();
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 =newRequest()
..contentType =newMediaType('application', 'xml');
xmlRequest.post(); // will be sent with content-type: application/xml
The text was updated successfully, but these errors were encountered:
rmconsole-wf
changed the title
Static methods on Http class do not allow content-type header to be explicitly set
WP-6213 Static methods on Http class do not allow content-type header to be explicitly set
Mar 9, 2018
Because the static request methods on the
Http
class are implemented by creating aRequest
instance and setting theuri
andheaders
fields, there is an issue where thecontent-type
header cannot be defined because theRequest
class is assumed to be of content-typetext/plain
. In other words, the following does not work as one would expect:The workaround is to construct the appropriate request class instance and modify the content-type via the
contentType
field:The text was updated successfully, but these errors were encountered: