Question

i have a problem with titanium to comunicate with a my server in the network, the server's ip is 192.168.0.208 on the port 8000 (is a Node.js server). If i call the server from the browser no problem but if i try to call the server from the application in Titanium i saw this error "The target server failed to respond" and in the server log no call is received

this is my network.js file in the application

    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;

and this is the coda that make the request

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);
    });
 };

what could be the error?

Was it helpful?

Solution

You must use "GET" not "get" :

network.request(url, "GET",undefined, function(resp) { ....
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top