最近使用 titanium mobile框架在开发一个ipad应用,在使用httpClient与后台数据交互时遇到了很棘手的问题:
httpClient的使用如下:
var httpClient = Titanium.Network.createHTTPClient();
function jspQuery(url,params){
var result = null;
httpClient.setTimeout(2000);
httpClient.onerror = function(e) {
Titanium.API.info('HTTP error: ' + e);
};
httpClient.open("POST", url, false);
httpClient.send(params);
}
httpClient.onload = function(){
var json = this.responseText;
var response = JSON.parse(json);
switch(response.page){
case "login":
doLogin(response);
break;
case "page1":
doRefresh(response);
break;
}
};
当后端请求的应用服务器为nginx时, httpClient.open("POST/GET", url, false); POST/GET一定大写,小写的话nginx会一直返回400错误,后端服务器为tomcat时大小写都能通过。千万别以为报400错误就是nginx的问题