OkHttp3 - 如何使用主机名主机构建 httpUrl?

OkHttp3 - How to build an httpUrl using a hostname host?

我有一个 OpenShift 应用程序用作我的应用程序服务器。

我有以下功能:

 public static HttpUrl.Builder getBaseHttpUrlBuilder(String path) {
        return new HttpUrl.Builder()
                .scheme("http")
                .host(SERVER_HOST)
                .port(SERVER_PORT)
                .addPathSegment(path);
    }

其中 SERVER_HOST = "http://my-server.1d35.starter-us-east-1.openshiftapps.com" .

当我在本地 运行 服务器时,即 SERVER_HOST = "127.0.0.1" 它运行良好。

不,我收到以下异常:

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.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)

如何使用主机名构建 OkHttp url?

提前致谢。

试试这个:

SERVER_HOST = "my-server.1d35.starter-us-east-1.openshiftapps.com"