1

Trying to interact with my API but the app won't even send the request :

var connectToAppbis = {
   login: function(login, password) {
         var params = {
                    "login": login,
                    "password": password
                };
         var url = "http://api.city1.fr/idstock/dev/v3/index.php/auth";
         var client = Ti.Network.createHTTPClient({
             // function called when the response data is available
             onload : function(e) {
                 Titanium.API.info(this.responseText);
                 var json = JSON.parse(this.responseText);
             },
             // function called when an error occurs, including a timeout
             onerror : function(e) {
                 Ti.API.debug(e.error);
                 alert('error');
             },
             timeout : 5000  // in milliseconds
         });
         // Prepare the connection.
         client.setRequestHeader("Content-Type", "application/json; charset=utf-8");
         client.open("POST", url);
         // Send the request.
         client.send(JSON.stringify(params));
    }
};

I added the permission on the manifest and i tried with and whithout the JSON.stringify(), what's wrong here ? Should i include something ? because on http://api.city1.fr/idstock/dev/v3/index.php/auth

I got a JSON value as expected ...

Errors logs:

[ERROR] :  TiHttpClient: (TiHttpClient-1) [15666,15666] HTTP Error (org.apache.http.client.HttpResponseException): Not Found
[ERROR] :  TiHttpClient: org.apache.http.client.HttpResponseException: Not Found
[ERROR] :  TiHttpClient:    at ti.modules.titanium.network.TiHTTPClient$LocalResponseHandler.handleResponse(TiHTTPClient.java:275)
[ERROR] :  TiHttpClient:    at ti.modules.titanium.network.TiHTTPClient$LocalResponseHandler.handleResponse(TiHTTPClient.java:219)
[ERROR] :  TiHttpClient:    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:974)
[ERROR] :  TiHttpClient:    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:954)
[ERROR] :  TiHttpClient:    at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1334)
[ERROR] :  TiHttpClient:    at java.lang.Thread.run(Thread.java:864)
Seba99
  • 1,197
  • 14
  • 38
  • 1
    It seems that the url you provided **only supports `GET` and not `POST`** http verb from server end. Also to test your webservices try using extensions like [Postman](https://addons.mozilla.org/de/firefox/addon/restclient/). – turtle May 04 '15 at 09:53
  • Hey ! That's true ! Wasn't searching at the rigth place ! Thanks :) ... Now it's ok with POST .. BUT seems like my params aren't send... With an `var_dump($_POST)` i don't have my params login and password ... Wrong header ? – Seba99 May 04 '15 at 10:21
  • you also don't need to stringify to POST! – Rene Pot May 04 '15 at 13:46
  • nevermind it was an header-value since the beginning ! should be : `application/x-www-form-urlencoded ` – Seba99 May 04 '15 at 14:13

0 Answers0