http - In Dart on server-side, how to set headers in HttpClient -
i trying use dart httpclient class (io library / server-side!) , can not think how equivalent of dart (client-side) call setrequestheader.
specifically want set "content-type" "application/json"
as per line (from client-side):
request.setrequestheader("content-type", "application/json");
i'm using format:
new httpclient().posturl(uri.parse(url)) .then((httpclientrequest request) => request.close()) .then((httpclientresponse response) => response.transform(new utf8decoder()).listen(_set_dbstats));
and when try insert:
.then((httpclientrequest request) => request.head("content-type", "application/json"))
i'm informed (in dart editor) head not method request... (although see in api?!) related being used post?
thanks in advance!
here snippet of working code evolved numerous tests , dealing issues outside scope of original question.
guenter zoechbauer heroically worked me off-line dones, not find examples of 1. server side, 2. post 3. http commands using headers, format permits this...
import 'package:http/http.dart' http; string url = "https://whatever.com"; return new http.client() .post(url, headers: {'content-type': 'application/json'}, body: '{"distinct": "users","key": "account","query": {"active":true}}') .whencomplete(() => print('completed')) .then((http.response r) => r.body); }
Comments
Post a Comment