Titanium JIRA Archive
Appcelerator Community (AC)

[AC-426] iOS: Network - HTTPClient call to ACS binding not working

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionCannot Reproduce
Resolution Date2015-11-21T18:44:10.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterManuel Conde Vendrell
AssigneeSharif AbuDarda
Created2014-08-10T14:49:13.000+0000
Updated2015-11-21T18:44:10.000+0000

Description

I'm tryiing to use my binds for my services in ACS. In Android is working well, but in iOS (emulator or device) any call I make to the bind, returns an xhr error "Unable to start HTTP connection". I tried to set my *acs-service-baseurl-* to *http://...*, to *https://...* and simply to my url without protocol, but with http the error changes to code 404 *HTTP error*, and with https is the same error as with nothing (current error). I debugged a bit the *InvokeService* but the error is simply that. This is the JSON error that appears when *InvokeService* calls xhr:
error: {"type":"error","source":{"cache":false},"code":6,"error":"Unable to start HTTP connection","success":false} 
As I said, in Android works fine. Any workaround will be welcome.

Comments

  1. Shuo Liang 2014-08-11

    Hi, Can you provide us a simple test case for your problem, that will be really helpful to address the it. Regards, Shuo
  2. Manuel Conde Vendrell 2014-08-11

    Sorry Shuo, just right now traveling for a week. I can give an example in one week. Anyway, the example is very basic, just calling any of the bindings generated by Studio automatically will fail on iOS and not in android. It is strange but I read some jiras about similar behavior before.
  3. Manuel Conde Vendrell 2014-08-26

    Sorry for the delay. Here is the code:
       /**
        * This is generated code - it will be overwritten. Do not modify.
        * Copyright (c) 2012 by Appcelerator, Inc. All Rights Reserved.
        */
       
       function InvokeService(path, method, data, cb) {
          if (typeof(data) == "function") {
             cb = data; data = null;
          }
          if (typeof(cb) !== "function")
             throw new Error("callback must be provided!");
          var xhr = Ti.Network.createHTTPClient();
          xhr.onerror = function(e) {
             cb(e.error);
          };
          xhr.onload = function(e) {
             var r = this.responseText;
             try {
                if (xhr.getResponseHeader("content-type").indexOf("json") != -1) {
                    r = JSON.parse(r);
                }
             } catch (E) {}
             cb(null, r);
          };
          if(exports.URL.match('/$') == '/' && path.indexOf('/') == 0) {
              xhr.open(method, exports.URL + path.substring(1));
          } else {
              xhr.open(method, exports.URL + path);
          }
          xhr.send(data);
       };
       
       var url = Ti.App.Properties.getString("acs-service-baseurl-mysite");
       
       if(!url) throw new Error("Url not found by acs-service-baseurl-mysite.");
       if(url.replace(/^\s+|\s+$/g, "")) {
          exports.URL = url.replace(/^\s+|\s+$/g, "");
       } else {
          exports.URL = "http://localhost:8080";
       }
       
       exports.api_getTopics = function(data, cb) {
          var path = [];
          path.push('/api/getTopics');
          InvokeService(path.join(''), "GET", data, cb);
       };
       
       exports.api_countSubscribers = function(data, cb) {
          var path = [];
          path.push('/api/countSubscribers');
          InvokeService(path.join(''), "GET", data, cb);
       };
       
    Any of the above calls work on iOS, but works on Android.
  4. Manuel Conde Vendrell 2014-09-16

    There is no one with this problem? Only me?

JSON Source