getting error “java.net.ConnectException: Failed to connect to” when i m trying API on android device....












-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










share|improve this question


















  • 1





    check this : stackoverflow.com/a/36811386/7319704

    – Abhinav Gupta
    Nov 14 '18 at 8:33











  • as i said, its not localhost api but on live server

    – Rahul Singh
    Nov 14 '18 at 8:35











  • for some reason your device has no access to your server.

    – Vladyslav Matviienko
    Nov 14 '18 at 8:38
















-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










share|improve this question


















  • 1





    check this : stackoverflow.com/a/36811386/7319704

    – Abhinav Gupta
    Nov 14 '18 at 8:33











  • as i said, its not localhost api but on live server

    – Rahul Singh
    Nov 14 '18 at 8:35











  • for some reason your device has no access to your server.

    – Vladyslav Matviienko
    Nov 14 '18 at 8:38














-1












-1








-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










share|improve this question














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







android rest






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 8:24









Rahul SinghRahul Singh

12




12








  • 1





    check this : stackoverflow.com/a/36811386/7319704

    – Abhinav Gupta
    Nov 14 '18 at 8:33











  • as i said, its not localhost api but on live server

    – Rahul Singh
    Nov 14 '18 at 8:35











  • for some reason your device has no access to your server.

    – Vladyslav Matviienko
    Nov 14 '18 at 8:38














  • 1





    check this : stackoverflow.com/a/36811386/7319704

    – Abhinav Gupta
    Nov 14 '18 at 8:33











  • as i said, its not localhost api but on live server

    – Rahul Singh
    Nov 14 '18 at 8:35











  • for some reason your device has no access to your server.

    – Vladyslav Matviienko
    Nov 14 '18 at 8:38








1




1





check this : stackoverflow.com/a/36811386/7319704

– Abhinav Gupta
Nov 14 '18 at 8:33





check this : stackoverflow.com/a/36811386/7319704

– Abhinav Gupta
Nov 14 '18 at 8:33













as i said, its not localhost api but on live server

– Rahul Singh
Nov 14 '18 at 8:35





as i said, its not localhost api but on live server

– Rahul Singh
Nov 14 '18 at 8:35













for some reason your device has no access to your server.

– Vladyslav Matviienko
Nov 14 '18 at 8:38





for some reason your device has no access to your server.

– Vladyslav Matviienko
Nov 14 '18 at 8:38












1 Answer
1






active

oldest

votes


















0














Did you add your internet permissions in your Manifest file?



<uses-permission android:name="android.permission.INTERNET" />





share|improve this answer
























  • i have already given this permission as many other APIs are working just fine in this app

    – Rahul Singh
    Nov 14 '18 at 8:29











  • Can you post your logcat of the error you are getting?

    – GoRo
    Nov 14 '18 at 8:32











  • java.net.ConnectException: Failed to connect to /139.xx.xx.xxx:xxxx

    – Rahul Singh
    Nov 14 '18 at 8: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 8:41











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53295781%2fgetting-error-java-net-connectexception-failed-to-connect-to-when-i-m-trying%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Did you add your internet permissions in your Manifest file?



<uses-permission android:name="android.permission.INTERNET" />





share|improve this answer
























  • i have already given this permission as many other APIs are working just fine in this app

    – Rahul Singh
    Nov 14 '18 at 8:29











  • Can you post your logcat of the error you are getting?

    – GoRo
    Nov 14 '18 at 8:32











  • java.net.ConnectException: Failed to connect to /139.xx.xx.xxx:xxxx

    – Rahul Singh
    Nov 14 '18 at 8: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 8:41
















0














Did you add your internet permissions in your Manifest file?



<uses-permission android:name="android.permission.INTERNET" />





share|improve this answer
























  • i have already given this permission as many other APIs are working just fine in this app

    – Rahul Singh
    Nov 14 '18 at 8:29











  • Can you post your logcat of the error you are getting?

    – GoRo
    Nov 14 '18 at 8:32











  • java.net.ConnectException: Failed to connect to /139.xx.xx.xxx:xxxx

    – Rahul Singh
    Nov 14 '18 at 8: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 8:41














0












0








0







Did you add your internet permissions in your Manifest file?



<uses-permission android:name="android.permission.INTERNET" />





share|improve this answer













Did you add your internet permissions in your Manifest file?



<uses-permission android:name="android.permission.INTERNET" />






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 8:26









GoRoGoRo

266




266













  • i have already given this permission as many other APIs are working just fine in this app

    – Rahul Singh
    Nov 14 '18 at 8:29











  • Can you post your logcat of the error you are getting?

    – GoRo
    Nov 14 '18 at 8:32











  • java.net.ConnectException: Failed to connect to /139.xx.xx.xxx:xxxx

    – Rahul Singh
    Nov 14 '18 at 8: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 8:41



















  • i have already given this permission as many other APIs are working just fine in this app

    – Rahul Singh
    Nov 14 '18 at 8:29











  • Can you post your logcat of the error you are getting?

    – GoRo
    Nov 14 '18 at 8:32











  • java.net.ConnectException: Failed to connect to /139.xx.xx.xxx:xxxx

    – Rahul Singh
    Nov 14 '18 at 8: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 8:41

















i have already given this permission as many other APIs are working just fine in this app

– Rahul Singh
Nov 14 '18 at 8:29





i have already given this permission as many other APIs are working just fine in this app

– Rahul Singh
Nov 14 '18 at 8:29













Can you post your logcat of the error you are getting?

– GoRo
Nov 14 '18 at 8:32





Can you post your logcat of the error you are getting?

– GoRo
Nov 14 '18 at 8:32













java.net.ConnectException: Failed to connect to /139.xx.xx.xxx:xxxx

– Rahul Singh
Nov 14 '18 at 8:36





java.net.ConnectException: Failed to connect to /139.xx.xx.xxx:xxxx

– Rahul Singh
Nov 14 '18 at 8: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 8:41





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 8:41


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53295781%2fgetting-error-java-net-connectexception-failed-to-connect-to-when-i-m-trying%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python