gpt4 book ai didi

javascript - 使用 json 调用 webService 在 Titanium 中出错,但使用 curl 从终端调用 webService 工作正常

转载 作者:行者123 更新时间:2023-11-30 18:32:45 28 4
gpt4 key购买 nike

您好,我正在尝试使用 json 在钛中调用 webService。该 webService 不接受任何参数,所以我只需要调用它。

这是我的代码:

var xhr = Titanium.Network.createHTTPClient();
xhr.setTimeout(10000);

xhr.open("POST","http://mytesturl.net/services/json/system.connect");
xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
xhr.send();
xhr.onerror = function() {

Titanium.API.info("some thing is wrong in calling");
};

xhr.onload = function() {

Titanium.API.info("The API response is " + this.responseText);
};

在日志中我得到这个错误:

The API response is {"#error":true,"#data":"Invalid method ","#response_code":405}

我以为 url 是错误的,但是当我尝试从我的终端调用相同的 Web 服务时,即使用 curl 实用程序

curl --data method=system.connect http://mytesturl.net/services/json

我得到了我需要的回应..我在这里做错了什么??

最佳答案

您没有将任何负载传递给服务器,而是尝试将方法作为 URL 的一部分进行传递。您需要将 method=system.connect 添加为 send 中的 data 参数函数调用并将 URL 更改为与 curl 请求中的相同 (http://mytesturl.net/services/json)。

关于javascript - 使用 json 调用 webService 在 Titanium 中出错,但使用 curl 从终端调用 webService 工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9127372/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com