android - Titanium android 设备 http 错误

标签 android http titanium titanium-mobile titanium-alloy

我在使用 Titanium 与网络中的服务器通信时遇到问题, 服务器的 ip 是端口 8000 上的 192.168.0.208(是 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);
    });
 };

可能是什么错误?

最佳答案

您必须使用“GET”而不是“get”:

network.request(url, "GET",undefined, function(resp) { ....

关于android - Titanium android 设备 http 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21856703/

相关文章:

android - ActionBarsherlock android.R.id.home <API 11

android - 如何在 Retrofit 1.9 中执行同步 api 调用

Android WebView “tel:” & "mailto:"链接显示未找到网页

c# - 有没有办法对超时错误进行单元测试?

android - ti中pdf文件放在哪里

iphone - PhoneGap 和 Appcelerator 在本地和远程存储数据?

android - 按格式化日期列对 sqlite 游标结果进行分组的方法

java - 如何限制传输速度?

python - 在 Django 中使用 HttpResponseRedirect 时如何传递模板上下文信息?

javascript - 钛自动更新剩余时间标签