[英]Calling RESTful webservices in Appcelerator Titanium Studio
我是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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.