dart - HttpRequest (web client) and HttpRequest (server): method and contentType doesn't exchange -
the method , contenttype parameters doesn't exchange in httprequest (web client) , httprequest (server) in dart.
i have following code:
(web client)
var url = "http://127.0.0.1:8087"; string jsonstring = json.encode(dadosregistro[id]); httprequest.request(url, method: "delete", senddata: jsonstring, mimetype: "application/json") .then((httprequest resp) { window.console.log(resp.response); }).catcherror(tratarerro);
(server)
httpserver.bind('127.0.0.1', 8087).then((server) { server.listen((httprequest request) { print(request.method); print(request.headers.contenttype); });
when web client calls server, result following:
options null
my expectative was:
delete application/json
am doing wrong?
thanks!
this cors issue. request receiving pre-flight request, sent browser verify if server can receive actual request. can see more cors here: http://www.html5rocks.com/en/tutorials/cors/
to see expected result, can change server code handle pre-flight request:
httpserver.bind('127.0.0.1', 8087).then((server) { server.listen((httprequest request) { request.response.headers.add("access-control-allow-origin", "*"); request.response.headers.add("access-control-allow-methods", "post,get,delete,put,options"); request.response.statuscode = httpstatus.ok; if (request.method == "options") { //pre-flight request request.response.close(); } else { print(request.method); print(request.headers.contenttype); request.response.close(); } });
Comments
Post a Comment