1

i am trying to call certain API, which is working fine if i test it on laptop(postman) but when i use it in my app its gives exception.

        RequestParams params = new RequestParams();
        params.add("comapanyName",jsonObject.getString("company_name"));

        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        asyncHttpClient.post(url, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                String s = new String(responseBody);
                Log.i("RESPONSE_INSERT", s);
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
                    Log.i("RESPONSE_ERROR_I", e.getMessage());

            }
        });

Its not local API but on server

Rahul Singh
  • 41
  • 1
  • 5

1 Answers1

3

Did you add your internet permissions in your Manifest file?

<uses-permission android:name="android.permission.INTERNET" />
GoRo
  • 132
  • 6
  • i have already given this permission as many other APIs are working just fine in this app – Rahul Singh Nov 14 '18 at 08:29
  • Can you post your logcat of the error you are getting? – GoRo Nov 14 '18 at 08:32
  • `java.net.ConnectException: Failed to connect to /139.xx.xx.xxx:xxxx` – Rahul Singh Nov 14 '18 at 08:36
  • It seems like you are connecting to an external IP outside your current LAN network, make sure that if you server is hosted externally using a port that the incoming IP / Range is allowed on your server. You can check PHP.ini guides out there, there are many of them. – GoRo Nov 14 '18 at 08:41