当我尝试使用geting方法获取访问URL时,
D/OkHttp: <-- HTTP FAILED: java.net.UnknownHostException: Unable to resolve host "xyz.aaa.net": No address associated with hostname
但是我在POST MAN中获得成功响应。已经两天了,但是没有任何线索。由于自动处理的问题,将实际URL更改为xyz.aaa.net。对不起:
Call<Response> call2 = apiInterface.getEmployeeListNew("1190",1008,"true"
);
call2.enqueue(new Callback<Response>() {
@Override
public void onResponse(Call<TaxProResponse> call, Response<Response> response) { }
@Override
public void onFailure(Call<TaxProResponse> call, Throwable t) {
call.cancel();
}
});
API客户端:
class APIClient {
private static Retrofit retrofit = null;
static Retrofit getClient() {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
retrofit = new Retrofit.Builder()
.baseUrl("http://xyz.aaa.net/api/")
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();
return retrofit;
}
}
APIInterface:
@GET("Profile")
Call<Response> getEmployeeListNew(
@Header("app_id") String app_id,
@Query("office_id") int office_id,
@Query("need_only_active") String need_only_active
);
整个网址都必须像这样,其中app_id为标头:
http://xyz.aaa.net/api/Profile?office_id=1008&need_only_active=true
如果任何人之前都遇到过此问题,请提出建议。 尝试了其他请求,它工作正常。提供许可,
<uses-permission android:name="android.permission.INTERNET"/>
它不像Stackoverflow中的其他问题那样发出许可。尝试了那里的解决方案,但不起作用。
这里要求的是完整日志
06-25 12:11:38.143 8450-8450/? I/zygote64: Late-enabling -Xcheck:jni
06-25 12:11:38.436 8450-8450/com.journaldev.retrofitintro D/NetworkSecurityConfig: No Network Security Config specified, using platform default
06-25 12:11:38.495 8450-8469/com.journaldev.retrofitintro D/OkHttp: --> GET http://xyz.aaa.net/api/AMTPProfile?office_id=1008&need_only_active=true http/1.1
app_id: 1190
06-25 12:11:38.497 8450-8469/com.journaldev.retrofitintro D/OkHttp: --> END GET
06-25 12:11:38.516 8450-8471/com.journaldev.retrofitintro D/OpenGLRenderer: HWUI GL Pipeline
06-25 12:11:38.561 8450-8471/com.journaldev.retrofitintro I/Adreno: QUALCOMM build : 8e59954, I0be83d0d26
Build Date : 09/22/17
OpenGL ES Shader Compiler Version: EV031.21.02.00
Local Branch : O17A
Remote Branch :
Remote Branch :
Reconstruct Branch :
06-25 12:11:38.564 8450-8471/com.journaldev.retrofitintro D/vndksupport: Loading /vendor/lib64/hw/gralloc.msm8994.so from current namespace instead of sphal namespace.
06-25 12:11:38.581 8450-8471/com.journaldev.retrofitintro I/Adreno: PFP: 0x00000000, ME: 0x00000000
06-25 12:11:38.598 8450-8471/com.journaldev.retrofitintro I/zygote64: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
06-25 12:11:38.602 8450-8471/com.journaldev.retrofitintro I/OpenGLRenderer: Initialized EGL, version 1.4
06-25 12:11:38.603 8450-8471/com.journaldev.retrofitintro D/OpenGLRenderer: Swap behavior 2
06-25 12:11:38.622 8450-8471/com.journaldev.retrofitintro D/vndksupport: Loading /vendor/lib64/hw/android.hardware.graphics.mapper@2.0-impl.so from current namespace instead of sphal namespace.
Loading /vendor/lib64/hw/gralloc.msm8994.so from current namespace instead of sphal namespace.
06-25 12:11:41.808 8450-8469/com.journaldev.retrofitintro D/OkHttp: <-- HTTP FAILED: java.net.UnknownHostException: Unable to resolve host "xyz.aaa.net": No address associated with hostname
谢谢。