簡體   English   中英

將POST與core-ajax-dart結合使用以將JSON數據發送到服務器REST API時遇到問題

[英]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時不起作用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM