HTTP FAILED: java.net.SocketTimeoutException: timeout on new Android gradle
up vote
1
down vote
favorite
I'm using
classpath 'com.android.tools.build:gradle:3.2.1'
distributionUrl=https://services.gradle.org/distributions/gradle-4.10.2-all.zip
and every time I try to connect to my server API it times out.
HTTP FAILED: java.net.SocketTimeoutException
My server API is perfectly fine and I've tested it with Postman & Direct URL. The only way to fix this is to downgrade to 3.0.4 gradle plugin or connect android device to VPN. I'm from IRAN I doubt that if there is any access issues to my servers from my country. I even tried setting long timeouts for my HTTPClient but I still get the same error on every single API. However after 20-30 retries I can finally receive only 1 successful response.
I'm using Retrofit2.
I also tried setting this in my manifest but nothing changed
android:usesCleartextTraffic="true"
Anyone else struggling with this problem? Anyone have a solution?
java android http timeout retrofit2
add a comment |
up vote
1
down vote
favorite
I'm using
classpath 'com.android.tools.build:gradle:3.2.1'
distributionUrl=https://services.gradle.org/distributions/gradle-4.10.2-all.zip
and every time I try to connect to my server API it times out.
HTTP FAILED: java.net.SocketTimeoutException
My server API is perfectly fine and I've tested it with Postman & Direct URL. The only way to fix this is to downgrade to 3.0.4 gradle plugin or connect android device to VPN. I'm from IRAN I doubt that if there is any access issues to my servers from my country. I even tried setting long timeouts for my HTTPClient but I still get the same error on every single API. However after 20-30 retries I can finally receive only 1 successful response.
I'm using Retrofit2.
I also tried setting this in my manifest but nothing changed
android:usesCleartextTraffic="true"
Anyone else struggling with this problem? Anyone have a solution?
java android http timeout retrofit2
Mohmmad hossein for using android studio you need use VPN and nothing.
– amir133
Nov 14 at 19:04
@amir133 there is no problem with building or installing the application. the problem is runtime, I can't connect to my server apis
– Mohammad Hosein Kalantarian
Nov 15 at 7:07
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm using
classpath 'com.android.tools.build:gradle:3.2.1'
distributionUrl=https://services.gradle.org/distributions/gradle-4.10.2-all.zip
and every time I try to connect to my server API it times out.
HTTP FAILED: java.net.SocketTimeoutException
My server API is perfectly fine and I've tested it with Postman & Direct URL. The only way to fix this is to downgrade to 3.0.4 gradle plugin or connect android device to VPN. I'm from IRAN I doubt that if there is any access issues to my servers from my country. I even tried setting long timeouts for my HTTPClient but I still get the same error on every single API. However after 20-30 retries I can finally receive only 1 successful response.
I'm using Retrofit2.
I also tried setting this in my manifest but nothing changed
android:usesCleartextTraffic="true"
Anyone else struggling with this problem? Anyone have a solution?
java android http timeout retrofit2
I'm using
classpath 'com.android.tools.build:gradle:3.2.1'
distributionUrl=https://services.gradle.org/distributions/gradle-4.10.2-all.zip
and every time I try to connect to my server API it times out.
HTTP FAILED: java.net.SocketTimeoutException
My server API is perfectly fine and I've tested it with Postman & Direct URL. The only way to fix this is to downgrade to 3.0.4 gradle plugin or connect android device to VPN. I'm from IRAN I doubt that if there is any access issues to my servers from my country. I even tried setting long timeouts for my HTTPClient but I still get the same error on every single API. However after 20-30 retries I can finally receive only 1 successful response.
I'm using Retrofit2.
I also tried setting this in my manifest but nothing changed
android:usesCleartextTraffic="true"
Anyone else struggling with this problem? Anyone have a solution?
java android http timeout retrofit2
java android http timeout retrofit2
asked Nov 14 at 18:54
Mohammad Hosein Kalantarian
62
62
Mohmmad hossein for using android studio you need use VPN and nothing.
– amir133
Nov 14 at 19:04
@amir133 there is no problem with building or installing the application. the problem is runtime, I can't connect to my server apis
– Mohammad Hosein Kalantarian
Nov 15 at 7:07
add a comment |
Mohmmad hossein for using android studio you need use VPN and nothing.
– amir133
Nov 14 at 19:04
@amir133 there is no problem with building or installing the application. the problem is runtime, I can't connect to my server apis
– Mohammad Hosein Kalantarian
Nov 15 at 7:07
Mohmmad hossein for using android studio you need use VPN and nothing.
– amir133
Nov 14 at 19:04
Mohmmad hossein for using android studio you need use VPN and nothing.
– amir133
Nov 14 at 19:04
@amir133 there is no problem with building or installing the application. the problem is runtime, I can't connect to my server apis
– Mohammad Hosein Kalantarian
Nov 15 at 7:07
@amir133 there is no problem with building or installing the application. the problem is runtime, I can't connect to my server apis
– Mohammad Hosein Kalantarian
Nov 15 at 7:07
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
I found the problem! It was a problem with self-signed SSL servers. Here's the fix:
you have to create an UnsafeClient class and then set it to retrofit's client.
public class UnsafeOkHttpClient {
public static OkHttpClient getUnsafeOkHttpClient() {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager trustAllCerts = new TrustManager {
new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate chain, String authType) throws CertificateException {
}
@Override
public java.security.cert.X509Certificate getAcceptedIssuers() {
return new java.security.cert.X509Certificate{};
}
}
};
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.sslSocketFactory(sslSocketFactory, (X509TrustManager)trustAllCerts[0]);
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
OkHttpClient okHttpClient = builder.build();
return okHttpClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
OkHttpClient okHttpClient = UnsafeOkHttpClient.getUnsafeOkHttpClient();
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl("BASEURL")
.client(okHttpClient);
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
I found the problem! It was a problem with self-signed SSL servers. Here's the fix:
you have to create an UnsafeClient class and then set it to retrofit's client.
public class UnsafeOkHttpClient {
public static OkHttpClient getUnsafeOkHttpClient() {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager trustAllCerts = new TrustManager {
new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate chain, String authType) throws CertificateException {
}
@Override
public java.security.cert.X509Certificate getAcceptedIssuers() {
return new java.security.cert.X509Certificate{};
}
}
};
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.sslSocketFactory(sslSocketFactory, (X509TrustManager)trustAllCerts[0]);
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
OkHttpClient okHttpClient = builder.build();
return okHttpClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
OkHttpClient okHttpClient = UnsafeOkHttpClient.getUnsafeOkHttpClient();
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl("BASEURL")
.client(okHttpClient);
add a comment |
up vote
0
down vote
accepted
I found the problem! It was a problem with self-signed SSL servers. Here's the fix:
you have to create an UnsafeClient class and then set it to retrofit's client.
public class UnsafeOkHttpClient {
public static OkHttpClient getUnsafeOkHttpClient() {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager trustAllCerts = new TrustManager {
new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate chain, String authType) throws CertificateException {
}
@Override
public java.security.cert.X509Certificate getAcceptedIssuers() {
return new java.security.cert.X509Certificate{};
}
}
};
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.sslSocketFactory(sslSocketFactory, (X509TrustManager)trustAllCerts[0]);
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
OkHttpClient okHttpClient = builder.build();
return okHttpClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
OkHttpClient okHttpClient = UnsafeOkHttpClient.getUnsafeOkHttpClient();
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl("BASEURL")
.client(okHttpClient);
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
I found the problem! It was a problem with self-signed SSL servers. Here's the fix:
you have to create an UnsafeClient class and then set it to retrofit's client.
public class UnsafeOkHttpClient {
public static OkHttpClient getUnsafeOkHttpClient() {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager trustAllCerts = new TrustManager {
new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate chain, String authType) throws CertificateException {
}
@Override
public java.security.cert.X509Certificate getAcceptedIssuers() {
return new java.security.cert.X509Certificate{};
}
}
};
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.sslSocketFactory(sslSocketFactory, (X509TrustManager)trustAllCerts[0]);
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
OkHttpClient okHttpClient = builder.build();
return okHttpClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
OkHttpClient okHttpClient = UnsafeOkHttpClient.getUnsafeOkHttpClient();
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl("BASEURL")
.client(okHttpClient);
I found the problem! It was a problem with self-signed SSL servers. Here's the fix:
you have to create an UnsafeClient class and then set it to retrofit's client.
public class UnsafeOkHttpClient {
public static OkHttpClient getUnsafeOkHttpClient() {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager trustAllCerts = new TrustManager {
new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate chain, String authType) throws CertificateException {
}
@Override
public java.security.cert.X509Certificate getAcceptedIssuers() {
return new java.security.cert.X509Certificate{};
}
}
};
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.sslSocketFactory(sslSocketFactory, (X509TrustManager)trustAllCerts[0]);
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
OkHttpClient okHttpClient = builder.build();
return okHttpClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
OkHttpClient okHttpClient = UnsafeOkHttpClient.getUnsafeOkHttpClient();
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl("BASEURL")
.client(okHttpClient);
answered Nov 22 at 2:29
Mohammad Hosein Kalantarian
62
62
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53306992%2fhttp-failed-java-net-sockettimeoutexception-timeout-on-new-android-gradle%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
Mohmmad hossein for using android studio you need use VPN and nothing.
– amir133
Nov 14 at 19:04
@amir133 there is no problem with building or installing the application. the problem is runtime, I can't connect to my server apis
– Mohammad Hosein Kalantarian
Nov 15 at 7:07