我是Appcelerator钛工作室的新手。您能否帮我解决如何在Appcelerator Titan中调用Web服务(基于Java)。
最佳答案
您可以使用Titanium.Network.HTTPClient进行RESTful调用。
GET请求的示例
var url = "http://www.appcelerator.com";
var client = Ti.Network.createHTTPClient({
// function called when the response data is available
onload : function(e) {
Ti.API.info("Received text: " + this.responseText);
alert('success');
},
// function called when an error occurs, including a timeout
onerror : function(e) {
Ti.API.debug(e.error);
alert('error');
},
timeout : 5000 // in milliseconds
});
// Prepare the connection.
client.open("GET", url);
// Send the request.
client.send();
POST请求的示例
var xhr = Ti.Network.createHTTPClient();
xhr.onload = function(e) {
//handle response, which at minimum will be an HTTP status code
};
xhr.open('POST','http://www.myblog.com/post.php');
xhr.send({
title:'My awesome blog',
body:'Today I met Susy at the laundromat. Best day EVAR\!'
});
它支持动词GET,POST,DELETE,PUT,PATCH
关于javascript - 在Appcelerator Titanium Studio中调用RESTful Web服务,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31884205/