Reputation: 4254
Hi I am trying to call a webService in titanium using json. That webService does not take any argument so i just have to call it.
here is my code:
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);
};
on the log i get this error :
The API response is {"#error":true,"#data":"Invalid method ","#response_code":405}
I thought the url is wrong but when i tried to call the same web services from my terminal i.e by using curl
utility
curl --data method=system.connect http://mytesturl.net/services/json
i got the response what i needed.. what i am doing wrong here??
Upvotes: 1
Views: 860
Reputation: 4480
You're not passing any payload to the server, but instead try to pass the method as a part of the URL. You'll need to add the method=system.connect
as the data
argument in the send function call and change the URL to be same as in the curl request (http://mytesturl.net/services/json).
Upvotes: 2