var xhr=Titanium.Network.createHTTPClient({
onload:function(e){
if(this.status == '200'){
Ti.API.info('got my response, http status code ' + this.status);
if(this.readyState == 4){
var response=JSON.parse(this.responseText);
success = true;
}
else{
alert('HTTP Ready State != 4');
}
}
else{
alert('HTTP Error Response Status Code = '+this.status);
Ti.API.error("Error =>"+this.response);
}
},
});
xhr.onerror = function(e){
};
xhr.open("POST","http://localhost:23003/api/user?username=dp&password=123456" ,true);//ADD your URL
xhr.setRequestHeader("content-type", "application/json");
xhr.send(); // Taa da
您好,上面提到的是我的代码,我正在尝试将帖子请求发送到 open 方法中提到的本地服务器进程。但我使用了一些控制台消息来查看返回的对象
我不知道我错在哪里。任何帮助将不胜感激。谢谢你的时间。
答案 0 :(得分:2)
您的服务器端代码看起来有问题,因为以下内容:
var xhr = Ti.Network.createHTTPClient({
onload: function(e) {
console.info(this.status);
console.info(this.readyState);
console.info(this.responseText);
}
});
xhr.open("POST", "http://requestb.in/ynwa0gyn");
xhr.setRequestHeader("content-type", "application/json");
xhr.send();
正确地给出:
[INFO] 200
[INFO] 4
[INFO] ok
访问http://requestb.in/ynwa0gyn?inspect以获取客户提出的请求。