您好,我正在尝试使用 json 在钛中调用 webService。该 webService 不接受任何参数,所以我只需要调用它。
Đây là mã của tôi:
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 TRONG dữ liệu
参数函数调用并将 URL 更改为与 curl 请求中的相同 (http://mytesturl.net/services/json)。
Tôi là một lập trình viên xuất sắc, rất giỏi!