您好我正在尝试使用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}
我认为网址错了,但当我尝试从终端拨打相同的网络服务时,即使用curl
实用程序
curl --data method=system.connect http://mytesturl.net/services/json
我得到了我需要的回复.. 我在这做错了什么?
答案 0 :(得分:2)
您没有将任何有效负载传递到服务器,而是尝试将该方法作为URL的一部分传递。您需要在send函数调用中添加method=system.connect
作为data
参数,并将URL更改为与curl请求中的相同(http://mytesturl.net/服务/ JSON)。