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