使用json调用webService在Titanium中会出现错误,但使用curl从终端调用webService效果良好
Calling webService using json gives error in Titanium but calling webService from terminal using curl works fine
嗨,我正在尝试使用json调用titanium中的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的一部分进行传递。您需要在send函数调用中添加method=system.connect
作为data
参数,并将URL更改为与curl请求中相同(http://mytesturl.net/services/json)。
相关文章:
- 如何从webservice中的数据表获取值到HTMLajax调用
- 使用 javascript 对 visualforce 页面上的 webservice url 进行 ajax 调用
- 使用node.js调用webservice时需要一些帮助
- Jquery没有在firefox浏览器中调用Webservice方法,它在Chrome和IE中运行良好
- 如何在 JavaScript 中创建列表参数来调用 WCF-Webservice
- 使用JavaScript调用WebService
- 将C#WebService调用到Android的Javascript
- 在不使用XMLHTTPRequest的情况下调用webservice并在Javascript中获取JSON响应
- 使用json调用webService在Titanium中会出现错误,但使用curl从终端调用webService效果良好
- ajax对webservice的调用总是会导致错误
- 如何使用javascript在titanium中调用WebService
- 如何使用BackboneJs调用asmx webservice进行集合
- 使用javascript调用HTML页面中的c# webservice函数
- 如何从ember调用webservice
- Access-Control-Allow-Origin'调用webservice时出现问题
- 可观察数组——调用webservice列出所有记录并将其绑定到一个表
- 从javascript调用webservice来刷新更新面板
- jQueryajax调用webservice以检索位图错误,代码为200
- 当用于ajax调用webservice的数据类型为json "时,如何将成功函数的结果与字符串进行比较
- 关于使用jQuery调用webservice的问题