无论如何都要从Titanium执行HTTP PUT / DELETE方法吗?他们支持吗?是否有任何第三方图书馆或解决方法处理它?</ p>
答案 0 :(得分:2)
是的,您可以在HTTPClient
中将PUT / DELETE作为动词发送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.
// This accepts PUT/DELETE/GET/POST
client.open("PUT", url);
// Send the request.
client.send();
答案 1 :(得分:0)
请注意,如果您尝试向主体添加参数,Titanium(HttpClient)会自动将DELETE转换为POST,并且不会给出任何明确的指示。必须在查询字符串中传递DELETE上的参数。
执行此转换的代码位于ASIHTTPRequest.m
中if ([self postLength] > 0) {
if ([requestMethod isEqualToString:@"GET"] || [requestMethod isEqualToString:@"DELETE"] || [requestMethod isEqualToString:@"HEAD"]) {
[self setRequestMethod:@"POST"];
}
[self addRequestHeader:@"Content-Length" value:[NSString stringWithFormat:@"%llu",[self postLength]]];
}
[self setHaveBuiltPostBody:YES];