![](/img/trans.png)
[英]java.lang.IllegalArgumentException: protocol = http host = null
[英]Retrofit Java.lang.IllegalArgumentException host == null
我正在使用Retrofit向Web服務發出一些請求,但是直到最近一切都出錯了,我才開始獲得標題中提到的異常。 我有一個基本的類,基本上是這樣的:
protected BaseService(int version) {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
if (cookieJar == null) {
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
cookieJar = new JavaNetCookieJar(cookieManager);
}
builder.cookieJar(cookieJar);
if (BuildConfig.IS_DEBUG) {
BASE_URL = "http://nasko.dev.trainingassetsgateway.com";
builder.interceptors().add(new Interceptor() {
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
Request newRequest = chain
.request()
.newBuilder()
.addHeader("Authorization", "Basic REMOVED")
.build();
return chain.proceed(newRequest);
}
});
} else {
BASE_URL = "https://trainingassetsgateway.com";
}
API_URL = BASE_URL + "/mapi/" + version + "/";
client = new Retrofit
.Builder()
.baseUrl(API_URL)
.client(okHttpClient = builder.build())
.addConverterFactory(GsonConverterFactory.create())
.build();
}
問題始於攔截鏈。 我已經將其追溯到HttpEngine.createAddress方法,其中正在創建Address的新實例。
如圖所示,URL的主機部分在那里,但是稍后在堆棧中的下一個調用中,“ uriHost”為null,而它應該與在“ Watches”窗口中看到的相同。
從那里到達主機為空並引發異常的地步。 我是在做錯什么還是可能錯過了什么?
如果有人參與,只需刪除手機上的應用即可。 我希望我早點做...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.