[英]Trouble using POST with core-ajax-dart to send JSON data to a server REST API
我無法使用core-ajax-dart將JSON數據發送到我的自定義REST服務器。 我可以使用以下命令成功發送JSON數據
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"));
但是當我嘗試用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()
;
它失敗了
Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
就我所看到的,core-ajax-dart方法應該如廣告所示那樣,有人可以告訴我我在做什么錯嗎?
澄清:我已經在使用CORS,並且第一個HttpRequest.request可以正常工作,只是在嘗試使用core-ajax-dart進行POST時不起作用
似乎您需要在服務器上設置CORS標頭。
看到
-DART中的客戶端與PHP中的服務器通信:訪問控制允許缺少原始標頭
-dart服務器/ angulardart和CORS問題
- 使用Dart進行CORS,如何使它工作?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.