【发布时间】:2014-02-18 14:25:27
【问题描述】:
我在与网络中的服务器通信时遇到了钛问题, 服务器的 ip 是 192.168.0.208 端口 8000(是一个 Node.js 服务器)。 如果我从浏览器调用服务器没问题,但如果我尝试从 Titanium 中的应用程序调用服务器,我看到此错误“目标服务器无法响应”,并且在服务器日志中没有收到呼叫
这是我在应用程序中的 network.js 文件
function HttpRequest(url, type, args, functionOnSuccss,functionOnError,timeout) {
// args is json parameters OPTIONAL
Ti.API.log("[HTTP REQ] Call" + url);
// ---# ok string ------
var xhr = Titanium.Network.createHTTPClient();
xhr.open(type,url);
xhr.cache = false;
xhr.enableKeepAlive = false;
xhr.timeout = timeout ? timeout : 500000;
xhr.setRequestHeader("Content-type", "application/json");
// xhr.setRequestHeader("Cookie", 'JSESSIONID=' + cookie + '');
xhr.onload = function(e) {
Ti.API.info("[HTTP] Response" + this.responseText);
functionOnSuccss(this.responseText);
};
xhr.onerror = function(e) {
Ti.API.info("ERROR " + e.error);
// alert("Connection Error");
functionOnError(e.error);
};
if(args){
xhr.send(args);
}else{
xhr.send();
}
};
exports.request = HttpRequest;
这是发出请求的结尾
network = require('/library/network');
var sendCarrello = function() {
$.loader.visible = true;
$.carrelloCamminante.animate(a);
url = "192.168.0.208:8000/newMobileUser"; // or http://192.168.0.208:8000/newMobileUser it's the same
network.request(url, "get",undefined, function(resp) {
alert(resp);
$.loader.visible = false;
}, function(err) {
alert("error - "+""+err);
});
};
可能是什么错误?
【问题讨论】:
-
尝试设置 xhr.open(type,url);在 xhr.setRequestHeader("Content-type", "application/json"); 之后
-
@AndreaGiglio 不一样
-
尝试使用浏览器/curl 和 Titanium 客户端生成的标头记录整个请求,并进行比较以查看差异在哪里。最近我在 Titanium HTTPClient 中保存 cookie 时遇到问题,它也可能是 Content-Accept 标头中的错误值。
-
我只是尝试,但这不是解决方案,因为服务器接受所有内容类型的请求
标签: android http titanium titanium-mobile titanium-alloy