繁体   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