1

尝试与我的 API 交互,但应用程序甚至不会发送请求:

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

我在清单上添加了许可,我尝试使用和不使用JSON.stringify(),这里有什么问题?我应该包括一些东西吗?因为在http://api.city1.fr/idstock/dev/v3/index.php/auth

我得到了预期的JSON值......

错误日志:

[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)
4

0 回答 0