I am having trouble sending JSON data to my custom REST sever using core-ajax-dart. I can sucessfully send JSON data with the following
var host = window.location.hostname;
var data = JSON.encode(rows);
HttpRequest.request('http://$host:9999/services/directory/items/$instanceId', method: 'POST', mimeType: 'application/json', sendData: data).catchError((obj) {
print(obj);
}).then((HttpRequest val) {
print('response: ${val.responseText}');
}, onError: (e) => print("error"));
but when I try and do the same thing with core-ajax-dart,
<core-ajax-dart id="ajax"
response="{{ response }}"
handleAs="json"></core-ajax-dart>
$['ajax']
..url="http://$host:9999/services/directory/items/$instanceId"
..method = 'POST'
..contentType = 'application/json'
..body = JSON.encode(rows)
..go()
;
it fails with
Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
Can someone tell me what I'm doing wrong here, as as far as I can see the core-ajax-dart method should work as advertised?
CLARIFICATION: I'm already using CORS, and the first HttpRequest.request works fine, just not when trying to POST using core-ajax-dart
Seems you need to set CORS headers on the server.
see
- Client in DART comunicate with server in PHP: access control allow origin headers missing
- problems with dart-server/angulardart and CORS
- CORS with Dart, how do I get it to work?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.