Reputation: 9146
I have an OpenShift application which serves as my Application server.
I have the following function:
public static HttpUrl.Builder getBaseHttpUrlBuilder(String path) {
return new HttpUrl.Builder()
.scheme("http")
.host(SERVER_HOST)
.port(SERVER_PORT)
.addPathSegment(path);
}
Where SERVER_HOST = "http://my-server.1d35.starter-us-east-1.openshiftapps.com"
.
When I run the server locally, i.e. SERVER_HOST = "127.0.0.1"
it working good.
No I'm getting the following exception:
10-08 19:48:22.843 12923-13932/com.nprogramming.android.couponsapp E/LoginUtils: Error in Login: unexpected host: http://my-server.1d35.starter-us-east-1.openshiftapps.com
10-08 19:48:22.843 12923-13932/com.nprogramming.android.couponsapp W/System.err: java.lang.IllegalArgumentException: unexpected host: http://my-server.1d35.starter-us-east-1.openshiftapps.com
10-08 19:48:22.844 12923-13932/com.nprogramming.android.couponsapp W/System.err: at okhttp3.HttpUrl$Builder.host(HttpUrl.java:1027)
at com.nprogramming.android.couponsapp.Utils.LoginUtils.login(LoginUtils.java:65)
at com.nprogramming.android.couponsapp.Activities.LoginActivity$LoginTask.loadInBackground(LoginActivity.java:178)
at com.nprogramming.android.couponsapp.Activities.LoginActivity$LoginTask.loadInBackground(LoginActivity.java:166)
at android.support.v4.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:306)
at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:59)
at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:47)
at android.support.v4.content.ModernAsyncTask$2.call(ModernAsyncTask.java:138)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
How Do I build an OkHttp url using a hostname?
Thanks in advance.
Upvotes: 0
Views: 1799
Reputation: 6426
Try this:
SERVER_HOST = "my-server.1d35.starter-us-east-1.openshiftapps.com"
Upvotes: 1