Retrofit request throwing UnknownHostException behind VPN
So I'm having an issue that looks that it came straight out from the Twilight Zone.
Problem
I have to hit a REST API endpoint from a backend, the thing is that in order to hit that endpoint I need to go through a VPN. Otherwise the host is not reachable. On desktop everything works fine, I open Postman, hit the GET endpoint and get the response. However when I try to hit the same endpoint through my Android device Retrofit throws an UnknownHostException.
Context
The endpoint url is something like https://api.something.something.net/. I'm using dependency injection with Dagger, so I've a NetworkModule that looks like:
...
NetworkModule("https://api.something.something.net/")
...
@Module
class NetworkModule(
private val baseHost: String
)
...
@Provides
@Named("authInterceptor")
fun providesAuthInterceptor(
@Named("authToken") authToken: String
): Interceptor
return Interceptor chain ->
var request = chain.request()
request = request.newBuilder()
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer $authToken")
.build()
val response = chain.proceed(request)
...
@Provides
@Singleton
fun provideOkHttpClient(
curlInterceptor: CurlInterceptor,
@Named("authInterceptor") authInterceptor: Interceptor
): OkHttpClient
val builder = OkHttpClient.Builder()
builder.addInterceptor(authInterceptor)
builder.addInterceptor(curlInterceptor)
return builder.build()
...
@Provides
@Singleton
fun provideRetrofit(okHttpClient: OkHttpClient, gson: Gson): Retrofit
return Retrofit.Builder()
.baseUrl(baseHost)
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.client(okHttpClient)
.build()
Then I've a bunch of Repositories which are the ones doing the request through Retrofit:
class MyApiRepositoryImpl(
val myRetrofitApi: MyRetrofitApi,
val uiScheduler: Scheduler,
val backgroundScheduler: Scheduler
) : MyApiRepository
override fun getSomethingFromTheApi(): Observable<DataResource<List<ApiSomethingResponse>>>
return myRetrofitApi.getResponseFromEndpoint()
.map
if (it.isSuccessful)
DataResource(it.body()?.list!!, ResourceType.NETWORK_SUCCESS)
else
throw RuntimeException("Network request failed code $it.code()")
.subscribeOn(backgroundScheduler)
.observeOn(uiScheduler)
.toObservable()
And this is the Retrofit's API interface:
interface MyRetrofitApi
@GET("/v1/something/")
fun getResponseFromEndpoint(): Single<Response<ApiSomethingResponse>>
So, when I call this Repository method from my Interactor/UseCases it jumps straight through the onError and shows the UnknownHostException.
What I tried so far
- I switched Retrofit by Volley and later by Ion, just to be sure that wasn't something related to the rest client. I got the same exception in all cases:
java.net.UnknownHostException: Unable to resolve host "api.something.something.net": No address associated with hostname
com.android.volley.NoConnectionError: java.net.UnknownHostException: Unable to resolve host "api.something.something.net": No address associated with hostname
I tried every configuration possible with Retrofit and the OkHttpClient:
On OkHttpClient I tried setting the
followSslRedirectsto true and false.followRedirectsto true and false. SethostnameVerifierto allow any hostname to pass through. Set a SSLSocketFactory to allow any unsigned certificates to pass through.On my Manifest I set my
android:networkSecurityConfigto:
https://github.com/commonsguy/cwac-netsecurity/issues/5
I tested the App on my Android Device (Android Nougat), on Emulators with Nougat, Marshmellow and Oreo, and a Genymotion emulator with Nougat.
I tried hitting a random public endpoint (
https://jsonplaceholder.typicode.com/todos/1) and It worked perfectly. So this isn't an issue with the internet connection.I've these three permissions set on my Manifest:
android.permission.INTERNET
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_WIFI_STATE
It's super weird because I've an Interceptor set to convert all the requests into cURL requests, I copied and pasted the same request that is failing into Postman and works perfectly.
- On my laptop I'm using Cisco AnyConnect, on my Android device I'm using the Cisco AnyConnect App and AFAIK on the emulators and Genymotion it should use the same network than the hosting machine.
There's a couple of websites that are only visible through the VPN and I can see them on the devices and on the emulators. But the endpoint URL is still unreachable from the App.
Couple of weird things
Yes, this gets weirder. If I hit the endpoint through the Chrome browser in my device or in the emulator I got redirected into a login page, that's because I'm not sending the authorization token. Now If I check the network responses through chrome://inspect I can get the IP of the host. Now if I change the base url of the NetworkModule by the IP and I add this line to the authorization Interceptor:
@Provides
@Named("authInterceptor")
fun providesAuthInterceptor(
@Named("authToken") authToken: String
): Interceptor
return Interceptor chain ->
var request = chain.request()
request = request.newBuilder()
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer $authToken")
.build()
val response = chain.proceed(request)
response.newBuilder().code(HttpURLConnection.HTTP_SEE_OTHER).build() // <--- This one
Then I start getting:
11-13 13:56:01.084 4867-4867/com.something.myapp D/GetSomethingUseCase: javax.net.ssl.SSLPeerUnverifiedException: Hostname <BASE IP> not verified:
certificate: sha256/someShaString
DN: CN=something.server.net,OU=Title,O=Company Something, LLC,L=Some City,ST=SomeState,C=SomeCountryCode
subjectAltNames: [someServer1.com, someServer2.com, someServer3.com, someServer4.com, andSoOn.com]
I'm not sure if this is unrelated or if it's actually one step forward to fix it.
Any tip or advice is appreciated.
Thanks,
add a comment |
So I'm having an issue that looks that it came straight out from the Twilight Zone.
Problem
I have to hit a REST API endpoint from a backend, the thing is that in order to hit that endpoint I need to go through a VPN. Otherwise the host is not reachable. On desktop everything works fine, I open Postman, hit the GET endpoint and get the response. However when I try to hit the same endpoint through my Android device Retrofit throws an UnknownHostException.
Context
The endpoint url is something like https://api.something.something.net/. I'm using dependency injection with Dagger, so I've a NetworkModule that looks like:
...
NetworkModule("https://api.something.something.net/")
...
@Module
class NetworkModule(
private val baseHost: String
)
...
@Provides
@Named("authInterceptor")
fun providesAuthInterceptor(
@Named("authToken") authToken: String
): Interceptor
return Interceptor chain ->
var request = chain.request()
request = request.newBuilder()
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer $authToken")
.build()
val response = chain.proceed(request)
...
@Provides
@Singleton
fun provideOkHttpClient(
curlInterceptor: CurlInterceptor,
@Named("authInterceptor") authInterceptor: Interceptor
): OkHttpClient
val builder = OkHttpClient.Builder()
builder.addInterceptor(authInterceptor)
builder.addInterceptor(curlInterceptor)
return builder.build()
...
@Provides
@Singleton
fun provideRetrofit(okHttpClient: OkHttpClient, gson: Gson): Retrofit
return Retrofit.Builder()
.baseUrl(baseHost)
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.client(okHttpClient)
.build()
Then I've a bunch of Repositories which are the ones doing the request through Retrofit:
class MyApiRepositoryImpl(
val myRetrofitApi: MyRetrofitApi,
val uiScheduler: Scheduler,
val backgroundScheduler: Scheduler
) : MyApiRepository
override fun getSomethingFromTheApi(): Observable<DataResource<List<ApiSomethingResponse>>>
return myRetrofitApi.getResponseFromEndpoint()
.map
if (it.isSuccessful)
DataResource(it.body()?.list!!, ResourceType.NETWORK_SUCCESS)
else
throw RuntimeException("Network request failed code $it.code()")
.subscribeOn(backgroundScheduler)
.observeOn(uiScheduler)
.toObservable()
And this is the Retrofit's API interface:
interface MyRetrofitApi
@GET("/v1/something/")
fun getResponseFromEndpoint(): Single<Response<ApiSomethingResponse>>
So, when I call this Repository method from my Interactor/UseCases it jumps straight through the onError and shows the UnknownHostException.
What I tried so far
- I switched Retrofit by Volley and later by Ion, just to be sure that wasn't something related to the rest client. I got the same exception in all cases:
java.net.UnknownHostException: Unable to resolve host "api.something.something.net": No address associated with hostname
com.android.volley.NoConnectionError: java.net.UnknownHostException: Unable to resolve host "api.something.something.net": No address associated with hostname
I tried every configuration possible with Retrofit and the OkHttpClient:
On OkHttpClient I tried setting the
followSslRedirectsto true and false.followRedirectsto true and false. SethostnameVerifierto allow any hostname to pass through. Set a SSLSocketFactory to allow any unsigned certificates to pass through.On my Manifest I set my
android:networkSecurityConfigto:
https://github.com/commonsguy/cwac-netsecurity/issues/5
I tested the App on my Android Device (Android Nougat), on Emulators with Nougat, Marshmellow and Oreo, and a Genymotion emulator with Nougat.
I tried hitting a random public endpoint (
https://jsonplaceholder.typicode.com/todos/1) and It worked perfectly. So this isn't an issue with the internet connection.I've these three permissions set on my Manifest:
android.permission.INTERNET
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_WIFI_STATE
It's super weird because I've an Interceptor set to convert all the requests into cURL requests, I copied and pasted the same request that is failing into Postman and works perfectly.
- On my laptop I'm using Cisco AnyConnect, on my Android device I'm using the Cisco AnyConnect App and AFAIK on the emulators and Genymotion it should use the same network than the hosting machine.
There's a couple of websites that are only visible through the VPN and I can see them on the devices and on the emulators. But the endpoint URL is still unreachable from the App.
Couple of weird things
Yes, this gets weirder. If I hit the endpoint through the Chrome browser in my device or in the emulator I got redirected into a login page, that's because I'm not sending the authorization token. Now If I check the network responses through chrome://inspect I can get the IP of the host. Now if I change the base url of the NetworkModule by the IP and I add this line to the authorization Interceptor:
@Provides
@Named("authInterceptor")
fun providesAuthInterceptor(
@Named("authToken") authToken: String
): Interceptor
return Interceptor chain ->
var request = chain.request()
request = request.newBuilder()
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer $authToken")
.build()
val response = chain.proceed(request)
response.newBuilder().code(HttpURLConnection.HTTP_SEE_OTHER).build() // <--- This one
Then I start getting:
11-13 13:56:01.084 4867-4867/com.something.myapp D/GetSomethingUseCase: javax.net.ssl.SSLPeerUnverifiedException: Hostname <BASE IP> not verified:
certificate: sha256/someShaString
DN: CN=something.server.net,OU=Title,O=Company Something, LLC,L=Some City,ST=SomeState,C=SomeCountryCode
subjectAltNames: [someServer1.com, someServer2.com, someServer3.com, someServer4.com, andSoOn.com]
I'm not sure if this is unrelated or if it's actually one step forward to fix it.
Any tip or advice is appreciated.
Thanks,
add a comment |
So I'm having an issue that looks that it came straight out from the Twilight Zone.
Problem
I have to hit a REST API endpoint from a backend, the thing is that in order to hit that endpoint I need to go through a VPN. Otherwise the host is not reachable. On desktop everything works fine, I open Postman, hit the GET endpoint and get the response. However when I try to hit the same endpoint through my Android device Retrofit throws an UnknownHostException.
Context
The endpoint url is something like https://api.something.something.net/. I'm using dependency injection with Dagger, so I've a NetworkModule that looks like:
...
NetworkModule("https://api.something.something.net/")
...
@Module
class NetworkModule(
private val baseHost: String
)
...
@Provides
@Named("authInterceptor")
fun providesAuthInterceptor(
@Named("authToken") authToken: String
): Interceptor
return Interceptor chain ->
var request = chain.request()
request = request.newBuilder()
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer $authToken")
.build()
val response = chain.proceed(request)
...
@Provides
@Singleton
fun provideOkHttpClient(
curlInterceptor: CurlInterceptor,
@Named("authInterceptor") authInterceptor: Interceptor
): OkHttpClient
val builder = OkHttpClient.Builder()
builder.addInterceptor(authInterceptor)
builder.addInterceptor(curlInterceptor)
return builder.build()
...
@Provides
@Singleton
fun provideRetrofit(okHttpClient: OkHttpClient, gson: Gson): Retrofit
return Retrofit.Builder()
.baseUrl(baseHost)
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.client(okHttpClient)
.build()
Then I've a bunch of Repositories which are the ones doing the request through Retrofit:
class MyApiRepositoryImpl(
val myRetrofitApi: MyRetrofitApi,
val uiScheduler: Scheduler,
val backgroundScheduler: Scheduler
) : MyApiRepository
override fun getSomethingFromTheApi(): Observable<DataResource<List<ApiSomethingResponse>>>
return myRetrofitApi.getResponseFromEndpoint()
.map
if (it.isSuccessful)
DataResource(it.body()?.list!!, ResourceType.NETWORK_SUCCESS)
else
throw RuntimeException("Network request failed code $it.code()")
.subscribeOn(backgroundScheduler)
.observeOn(uiScheduler)
.toObservable()
And this is the Retrofit's API interface:
interface MyRetrofitApi
@GET("/v1/something/")
fun getResponseFromEndpoint(): Single<Response<ApiSomethingResponse>>
So, when I call this Repository method from my Interactor/UseCases it jumps straight through the onError and shows the UnknownHostException.
What I tried so far
- I switched Retrofit by Volley and later by Ion, just to be sure that wasn't something related to the rest client. I got the same exception in all cases:
java.net.UnknownHostException: Unable to resolve host "api.something.something.net": No address associated with hostname
com.android.volley.NoConnectionError: java.net.UnknownHostException: Unable to resolve host "api.something.something.net": No address associated with hostname
I tried every configuration possible with Retrofit and the OkHttpClient:
On OkHttpClient I tried setting the
followSslRedirectsto true and false.followRedirectsto true and false. SethostnameVerifierto allow any hostname to pass through. Set a SSLSocketFactory to allow any unsigned certificates to pass through.On my Manifest I set my
android:networkSecurityConfigto:
https://github.com/commonsguy/cwac-netsecurity/issues/5
I tested the App on my Android Device (Android Nougat), on Emulators with Nougat, Marshmellow and Oreo, and a Genymotion emulator with Nougat.
I tried hitting a random public endpoint (
https://jsonplaceholder.typicode.com/todos/1) and It worked perfectly. So this isn't an issue with the internet connection.I've these three permissions set on my Manifest:
android.permission.INTERNET
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_WIFI_STATE
It's super weird because I've an Interceptor set to convert all the requests into cURL requests, I copied and pasted the same request that is failing into Postman and works perfectly.
- On my laptop I'm using Cisco AnyConnect, on my Android device I'm using the Cisco AnyConnect App and AFAIK on the emulators and Genymotion it should use the same network than the hosting machine.
There's a couple of websites that are only visible through the VPN and I can see them on the devices and on the emulators. But the endpoint URL is still unreachable from the App.
Couple of weird things
Yes, this gets weirder. If I hit the endpoint through the Chrome browser in my device or in the emulator I got redirected into a login page, that's because I'm not sending the authorization token. Now If I check the network responses through chrome://inspect I can get the IP of the host. Now if I change the base url of the NetworkModule by the IP and I add this line to the authorization Interceptor:
@Provides
@Named("authInterceptor")
fun providesAuthInterceptor(
@Named("authToken") authToken: String
): Interceptor
return Interceptor chain ->
var request = chain.request()
request = request.newBuilder()
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer $authToken")
.build()
val response = chain.proceed(request)
response.newBuilder().code(HttpURLConnection.HTTP_SEE_OTHER).build() // <--- This one
Then I start getting:
11-13 13:56:01.084 4867-4867/com.something.myapp D/GetSomethingUseCase: javax.net.ssl.SSLPeerUnverifiedException: Hostname <BASE IP> not verified:
certificate: sha256/someShaString
DN: CN=something.server.net,OU=Title,O=Company Something, LLC,L=Some City,ST=SomeState,C=SomeCountryCode
subjectAltNames: [someServer1.com, someServer2.com, someServer3.com, someServer4.com, andSoOn.com]
I'm not sure if this is unrelated or if it's actually one step forward to fix it.
Any tip or advice is appreciated.
Thanks,
So I'm having an issue that looks that it came straight out from the Twilight Zone.
Problem
I have to hit a REST API endpoint from a backend, the thing is that in order to hit that endpoint I need to go through a VPN. Otherwise the host is not reachable. On desktop everything works fine, I open Postman, hit the GET endpoint and get the response. However when I try to hit the same endpoint through my Android device Retrofit throws an UnknownHostException.
Context
The endpoint url is something like https://api.something.something.net/. I'm using dependency injection with Dagger, so I've a NetworkModule that looks like:
...
NetworkModule("https://api.something.something.net/")
...
@Module
class NetworkModule(
private val baseHost: String
)
...
@Provides
@Named("authInterceptor")
fun providesAuthInterceptor(
@Named("authToken") authToken: String
): Interceptor
return Interceptor chain ->
var request = chain.request()
request = request.newBuilder()
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer $authToken")
.build()
val response = chain.proceed(request)
...
@Provides
@Singleton
fun provideOkHttpClient(
curlInterceptor: CurlInterceptor,
@Named("authInterceptor") authInterceptor: Interceptor
): OkHttpClient
val builder = OkHttpClient.Builder()
builder.addInterceptor(authInterceptor)
builder.addInterceptor(curlInterceptor)
return builder.build()
...
@Provides
@Singleton
fun provideRetrofit(okHttpClient: OkHttpClient, gson: Gson): Retrofit
return Retrofit.Builder()
.baseUrl(baseHost)
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.client(okHttpClient)
.build()
Then I've a bunch of Repositories which are the ones doing the request through Retrofit:
class MyApiRepositoryImpl(
val myRetrofitApi: MyRetrofitApi,
val uiScheduler: Scheduler,
val backgroundScheduler: Scheduler
) : MyApiRepository
override fun getSomethingFromTheApi(): Observable<DataResource<List<ApiSomethingResponse>>>
return myRetrofitApi.getResponseFromEndpoint()
.map
if (it.isSuccessful)
DataResource(it.body()?.list!!, ResourceType.NETWORK_SUCCESS)
else
throw RuntimeException("Network request failed code $it.code()")
.subscribeOn(backgroundScheduler)
.observeOn(uiScheduler)
.toObservable()
And this is the Retrofit's API interface:
interface MyRetrofitApi
@GET("/v1/something/")
fun getResponseFromEndpoint(): Single<Response<ApiSomethingResponse>>
So, when I call this Repository method from my Interactor/UseCases it jumps straight through the onError and shows the UnknownHostException.
What I tried so far
- I switched Retrofit by Volley and later by Ion, just to be sure that wasn't something related to the rest client. I got the same exception in all cases:
java.net.UnknownHostException: Unable to resolve host "api.something.something.net": No address associated with hostname
com.android.volley.NoConnectionError: java.net.UnknownHostException: Unable to resolve host "api.something.something.net": No address associated with hostname
I tried every configuration possible with Retrofit and the OkHttpClient:
On OkHttpClient I tried setting the
followSslRedirectsto true and false.followRedirectsto true and false. SethostnameVerifierto allow any hostname to pass through. Set a SSLSocketFactory to allow any unsigned certificates to pass through.On my Manifest I set my
android:networkSecurityConfigto:
https://github.com/commonsguy/cwac-netsecurity/issues/5
I tested the App on my Android Device (Android Nougat), on Emulators with Nougat, Marshmellow and Oreo, and a Genymotion emulator with Nougat.
I tried hitting a random public endpoint (
https://jsonplaceholder.typicode.com/todos/1) and It worked perfectly. So this isn't an issue with the internet connection.I've these three permissions set on my Manifest:
android.permission.INTERNET
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_WIFI_STATE
It's super weird because I've an Interceptor set to convert all the requests into cURL requests, I copied and pasted the same request that is failing into Postman and works perfectly.
- On my laptop I'm using Cisco AnyConnect, on my Android device I'm using the Cisco AnyConnect App and AFAIK on the emulators and Genymotion it should use the same network than the hosting machine.
There's a couple of websites that are only visible through the VPN and I can see them on the devices and on the emulators. But the endpoint URL is still unreachable from the App.
Couple of weird things
Yes, this gets weirder. If I hit the endpoint through the Chrome browser in my device or in the emulator I got redirected into a login page, that's because I'm not sending the authorization token. Now If I check the network responses through chrome://inspect I can get the IP of the host. Now if I change the base url of the NetworkModule by the IP and I add this line to the authorization Interceptor:
@Provides
@Named("authInterceptor")
fun providesAuthInterceptor(
@Named("authToken") authToken: String
): Interceptor
return Interceptor chain ->
var request = chain.request()
request = request.newBuilder()
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer $authToken")
.build()
val response = chain.proceed(request)
response.newBuilder().code(HttpURLConnection.HTTP_SEE_OTHER).build() // <--- This one
Then I start getting:
11-13 13:56:01.084 4867-4867/com.something.myapp D/GetSomethingUseCase: javax.net.ssl.SSLPeerUnverifiedException: Hostname <BASE IP> not verified:
certificate: sha256/someShaString
DN: CN=something.server.net,OU=Title,O=Company Something, LLC,L=Some City,ST=SomeState,C=SomeCountryCode
subjectAltNames: [someServer1.com, someServer2.com, someServer3.com, someServer4.com, andSoOn.com]
I'm not sure if this is unrelated or if it's actually one step forward to fix it.
Any tip or advice is appreciated.
Thanks,
edited Nov 14 '18 at 4:17
Shashanth
2,56242236
2,56242236
asked Nov 14 '18 at 2:27
4gus71n4gus71n
2,81512344
2,81512344
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I think this issue may be related to ssl certificate validity. for dealing with that issue you should to set setSSLSocketFactory in HttpClient.
private SSLConnectionSocketFactory getSSLSocketFactory()
KeyStore trustStore;
try
trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
TrustStrategy trustStrategy = new TrustStrategy()
@Override
public boolean isTrusted(X509Certificate chain, String authType)
throws CertificateException
return true;
;
SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
sslContextBuilder.loadTrustMaterial(trustStore, trustStrategy);
sslContextBuilder.useTLS();
SSLContext sslContext = sslContextBuilder.build();
SSLConnectionSocketFactory sslSocketFactory = new
SSLConnectionSocketFactory(sslContext);
return sslSocketFactory;
catch (GeneralSecurityException
HttpClientBuilder.create().setSSLSocketFactory(getSSLSocketFactory())
.build();
1
Sorry but what is socketFactory supposed to be?
– 4gus71n
Nov 14 '18 at 11:22
1
I updated the okhttp client library to the latest version and I cannot see that SSLConnectionSocketFactory class anywhere. What version are you using?
– 4gus71n
Nov 14 '18 at 15:43
Please check your code on fun provideOkHttpClient which is there you just set setSSLSocketFactory on instance you have got from okhttpclient like below: val builder = OkHttpClient.Builder(); builder.setSSLSocketFactory
– Amir
Nov 14 '18 at 17:25
1
I'm talking about this line:SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext);The SSLConnectionSocketFactory is not on my okhttp classes, what version are you using?
– 4gus71n
Nov 14 '18 at 17:32
1
Thanks for the link, but I've probably checked all the stackoverflow links related to this. That one too. I'm putting a bounty for 500, tomorrow for this. I really need to get this done or at least prove that I need something from the server-side.
– 4gus71n
Nov 14 '18 at 18:54
|
show 2 more comments
A coworker found the issue. Basically the VPN is blocking any App except com.android.chrome.
https://www.cisco.com/c/en/us/td/docs/security/vpn_client/anyconnect/anyconnect40/administration/guide/Cisco_AnyConnect_Mobile_Administrator_Guide_4-0/mobile-anyconnect-mobile-devices.html#task_F445916BDC9649D49A98F98224D2EA7D
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%2f53292330%2fretrofit-request-throwing-unknownhostexception-behind-vpn%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think this issue may be related to ssl certificate validity. for dealing with that issue you should to set setSSLSocketFactory in HttpClient.
private SSLConnectionSocketFactory getSSLSocketFactory()
KeyStore trustStore;
try
trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
TrustStrategy trustStrategy = new TrustStrategy()
@Override
public boolean isTrusted(X509Certificate chain, String authType)
throws CertificateException
return true;
;
SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
sslContextBuilder.loadTrustMaterial(trustStore, trustStrategy);
sslContextBuilder.useTLS();
SSLContext sslContext = sslContextBuilder.build();
SSLConnectionSocketFactory sslSocketFactory = new
SSLConnectionSocketFactory(sslContext);
return sslSocketFactory;
catch (GeneralSecurityException
HttpClientBuilder.create().setSSLSocketFactory(getSSLSocketFactory())
.build();
1
Sorry but what is socketFactory supposed to be?
– 4gus71n
Nov 14 '18 at 11:22
1
I updated the okhttp client library to the latest version and I cannot see that SSLConnectionSocketFactory class anywhere. What version are you using?
– 4gus71n
Nov 14 '18 at 15:43
Please check your code on fun provideOkHttpClient which is there you just set setSSLSocketFactory on instance you have got from okhttpclient like below: val builder = OkHttpClient.Builder(); builder.setSSLSocketFactory
– Amir
Nov 14 '18 at 17:25
1
I'm talking about this line:SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext);The SSLConnectionSocketFactory is not on my okhttp classes, what version are you using?
– 4gus71n
Nov 14 '18 at 17:32
1
Thanks for the link, but I've probably checked all the stackoverflow links related to this. That one too. I'm putting a bounty for 500, tomorrow for this. I really need to get this done or at least prove that I need something from the server-side.
– 4gus71n
Nov 14 '18 at 18:54
|
show 2 more comments
I think this issue may be related to ssl certificate validity. for dealing with that issue you should to set setSSLSocketFactory in HttpClient.
private SSLConnectionSocketFactory getSSLSocketFactory()
KeyStore trustStore;
try
trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
TrustStrategy trustStrategy = new TrustStrategy()
@Override
public boolean isTrusted(X509Certificate chain, String authType)
throws CertificateException
return true;
;
SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
sslContextBuilder.loadTrustMaterial(trustStore, trustStrategy);
sslContextBuilder.useTLS();
SSLContext sslContext = sslContextBuilder.build();
SSLConnectionSocketFactory sslSocketFactory = new
SSLConnectionSocketFactory(sslContext);
return sslSocketFactory;
catch (GeneralSecurityException
HttpClientBuilder.create().setSSLSocketFactory(getSSLSocketFactory())
.build();
1
Sorry but what is socketFactory supposed to be?
– 4gus71n
Nov 14 '18 at 11:22
1
I updated the okhttp client library to the latest version and I cannot see that SSLConnectionSocketFactory class anywhere. What version are you using?
– 4gus71n
Nov 14 '18 at 15:43
Please check your code on fun provideOkHttpClient which is there you just set setSSLSocketFactory on instance you have got from okhttpclient like below: val builder = OkHttpClient.Builder(); builder.setSSLSocketFactory
– Amir
Nov 14 '18 at 17:25
1
I'm talking about this line:SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext);The SSLConnectionSocketFactory is not on my okhttp classes, what version are you using?
– 4gus71n
Nov 14 '18 at 17:32
1
Thanks for the link, but I've probably checked all the stackoverflow links related to this. That one too. I'm putting a bounty for 500, tomorrow for this. I really need to get this done or at least prove that I need something from the server-side.
– 4gus71n
Nov 14 '18 at 18:54
|
show 2 more comments
I think this issue may be related to ssl certificate validity. for dealing with that issue you should to set setSSLSocketFactory in HttpClient.
private SSLConnectionSocketFactory getSSLSocketFactory()
KeyStore trustStore;
try
trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
TrustStrategy trustStrategy = new TrustStrategy()
@Override
public boolean isTrusted(X509Certificate chain, String authType)
throws CertificateException
return true;
;
SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
sslContextBuilder.loadTrustMaterial(trustStore, trustStrategy);
sslContextBuilder.useTLS();
SSLContext sslContext = sslContextBuilder.build();
SSLConnectionSocketFactory sslSocketFactory = new
SSLConnectionSocketFactory(sslContext);
return sslSocketFactory;
catch (GeneralSecurityException
HttpClientBuilder.create().setSSLSocketFactory(getSSLSocketFactory())
.build();
I think this issue may be related to ssl certificate validity. for dealing with that issue you should to set setSSLSocketFactory in HttpClient.
private SSLConnectionSocketFactory getSSLSocketFactory()
KeyStore trustStore;
try
trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
TrustStrategy trustStrategy = new TrustStrategy()
@Override
public boolean isTrusted(X509Certificate chain, String authType)
throws CertificateException
return true;
;
SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
sslContextBuilder.loadTrustMaterial(trustStore, trustStrategy);
sslContextBuilder.useTLS();
SSLContext sslContext = sslContextBuilder.build();
SSLConnectionSocketFactory sslSocketFactory = new
SSLConnectionSocketFactory(sslContext);
return sslSocketFactory;
catch (GeneralSecurityException
HttpClientBuilder.create().setSSLSocketFactory(getSSLSocketFactory())
.build();
edited Nov 14 '18 at 12:02
answered Nov 14 '18 at 7:03
AmirAmir
159214
159214
1
Sorry but what is socketFactory supposed to be?
– 4gus71n
Nov 14 '18 at 11:22
1
I updated the okhttp client library to the latest version and I cannot see that SSLConnectionSocketFactory class anywhere. What version are you using?
– 4gus71n
Nov 14 '18 at 15:43
Please check your code on fun provideOkHttpClient which is there you just set setSSLSocketFactory on instance you have got from okhttpclient like below: val builder = OkHttpClient.Builder(); builder.setSSLSocketFactory
– Amir
Nov 14 '18 at 17:25
1
I'm talking about this line:SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext);The SSLConnectionSocketFactory is not on my okhttp classes, what version are you using?
– 4gus71n
Nov 14 '18 at 17:32
1
Thanks for the link, but I've probably checked all the stackoverflow links related to this. That one too. I'm putting a bounty for 500, tomorrow for this. I really need to get this done or at least prove that I need something from the server-side.
– 4gus71n
Nov 14 '18 at 18:54
|
show 2 more comments
1
Sorry but what is socketFactory supposed to be?
– 4gus71n
Nov 14 '18 at 11:22
1
I updated the okhttp client library to the latest version and I cannot see that SSLConnectionSocketFactory class anywhere. What version are you using?
– 4gus71n
Nov 14 '18 at 15:43
Please check your code on fun provideOkHttpClient which is there you just set setSSLSocketFactory on instance you have got from okhttpclient like below: val builder = OkHttpClient.Builder(); builder.setSSLSocketFactory
– Amir
Nov 14 '18 at 17:25
1
I'm talking about this line:SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext);The SSLConnectionSocketFactory is not on my okhttp classes, what version are you using?
– 4gus71n
Nov 14 '18 at 17:32
1
Thanks for the link, but I've probably checked all the stackoverflow links related to this. That one too. I'm putting a bounty for 500, tomorrow for this. I really need to get this done or at least prove that I need something from the server-side.
– 4gus71n
Nov 14 '18 at 18:54
1
1
Sorry but what is socketFactory supposed to be?
– 4gus71n
Nov 14 '18 at 11:22
Sorry but what is socketFactory supposed to be?
– 4gus71n
Nov 14 '18 at 11:22
1
1
I updated the okhttp client library to the latest version and I cannot see that SSLConnectionSocketFactory class anywhere. What version are you using?
– 4gus71n
Nov 14 '18 at 15:43
I updated the okhttp client library to the latest version and I cannot see that SSLConnectionSocketFactory class anywhere. What version are you using?
– 4gus71n
Nov 14 '18 at 15:43
Please check your code on fun provideOkHttpClient which is there you just set setSSLSocketFactory on instance you have got from okhttpclient like below: val builder = OkHttpClient.Builder(); builder.setSSLSocketFactory
– Amir
Nov 14 '18 at 17:25
Please check your code on fun provideOkHttpClient which is there you just set setSSLSocketFactory on instance you have got from okhttpclient like below: val builder = OkHttpClient.Builder(); builder.setSSLSocketFactory
– Amir
Nov 14 '18 at 17:25
1
1
I'm talking about this line:
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext); The SSLConnectionSocketFactory is not on my okhttp classes, what version are you using?– 4gus71n
Nov 14 '18 at 17:32
I'm talking about this line:
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext); The SSLConnectionSocketFactory is not on my okhttp classes, what version are you using?– 4gus71n
Nov 14 '18 at 17:32
1
1
Thanks for the link, but I've probably checked all the stackoverflow links related to this. That one too. I'm putting a bounty for 500, tomorrow for this. I really need to get this done or at least prove that I need something from the server-side.
– 4gus71n
Nov 14 '18 at 18:54
Thanks for the link, but I've probably checked all the stackoverflow links related to this. That one too. I'm putting a bounty for 500, tomorrow for this. I really need to get this done or at least prove that I need something from the server-side.
– 4gus71n
Nov 14 '18 at 18:54
|
show 2 more comments
A coworker found the issue. Basically the VPN is blocking any App except com.android.chrome.
https://www.cisco.com/c/en/us/td/docs/security/vpn_client/anyconnect/anyconnect40/administration/guide/Cisco_AnyConnect_Mobile_Administrator_Guide_4-0/mobile-anyconnect-mobile-devices.html#task_F445916BDC9649D49A98F98224D2EA7D
add a comment |
A coworker found the issue. Basically the VPN is blocking any App except com.android.chrome.
https://www.cisco.com/c/en/us/td/docs/security/vpn_client/anyconnect/anyconnect40/administration/guide/Cisco_AnyConnect_Mobile_Administrator_Guide_4-0/mobile-anyconnect-mobile-devices.html#task_F445916BDC9649D49A98F98224D2EA7D
add a comment |
A coworker found the issue. Basically the VPN is blocking any App except com.android.chrome.
https://www.cisco.com/c/en/us/td/docs/security/vpn_client/anyconnect/anyconnect40/administration/guide/Cisco_AnyConnect_Mobile_Administrator_Guide_4-0/mobile-anyconnect-mobile-devices.html#task_F445916BDC9649D49A98F98224D2EA7D
A coworker found the issue. Basically the VPN is blocking any App except com.android.chrome.
https://www.cisco.com/c/en/us/td/docs/security/vpn_client/anyconnect/anyconnect40/administration/guide/Cisco_AnyConnect_Mobile_Administrator_Guide_4-0/mobile-anyconnect-mobile-devices.html#task_F445916BDC9649D49A98F98224D2EA7D
answered Nov 16 '18 at 22:33
4gus71n4gus71n
2,81512344
2,81512344
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.
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%2f53292330%2fretrofit-request-throwing-unknownhostexception-behind-vpn%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