getting error “java.net.ConnectException: Failed to connect to” when i m trying API on android device....
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
add a comment |
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
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
add a comment |
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
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
android rest
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
Did you add your internet permissions in your Manifest file?
<uses-permission android:name="android.permission.INTERNET" />
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Did you add your internet permissions in your Manifest file?
<uses-permission android:name="android.permission.INTERNET" />
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
add a comment |
Did you add your internet permissions in your Manifest file?
<uses-permission android:name="android.permission.INTERNET" />
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
add a comment |
Did you add your internet permissions in your Manifest file?
<uses-permission android:name="android.permission.INTERNET" />
Did you add your internet permissions in your Manifest file?
<uses-permission android:name="android.permission.INTERNET" />
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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