在我的Android应用程序中,我需要调用具有对服务器的自动识别的Rest Web服务 这是我的代码的一部分:
public static final String API_URL = "http://adm-erp-tst1.adm.gov.sa:8001/webservices/rest/mobilesvc/";
private static OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
String credentials = "login" + ":" + "password";
final String basic =
"Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
httpClient.addInterceptor(new Interceptor() {
@Override
public okhttp3.Response intercept(Interceptor.Chain chain) throws IOException {
Request original = chain.request();
Request.Builder requestBuilder = original.newBuilder()
.addHeader("Authorization", basic)
.addHeader("Accept", "application/json")
.addHeader("Content-Type", "application/json")
.method(original.method(), original.body());
Request request = requestBuilder.build();
return chain.proceed(request);
}
});
输出日志:
Retrofit response onResponse msg : Unauthorized........and .. response code : 401
我确信登录名和密码是正确的。
我非常感谢您提供的任何帮助。
更新:
05-11 09:28:52.970 19171-19269/com.ites.makkahleave.mobileerp
D/OkHttp: --> POST http://adm-erp-tst1.adm.gov.sa:8001/webservices/rest/mobilesvc/validate_user_login/ http/1.1
05-11 09:28:52.970 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: Content-Type: application/json; charset=UTF-8
05-11 09:28:52.970 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: Content-Length: 369
05-11 09:28:52.970 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: {"VALIDATE_USER_LOGIN_input":{"RESTHeader":{"NLSLanguage":"AMERICAN","RespApplication":"SYSTEM_ADMINISTRATOR","SecurityGroup":"STANDARD","@xmlns":"http://xmlns.oracle.com/apps/per/soaprovider/plsql/rest/mobilesvc/header"}}}
05-11 09:28:52.970 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: --> END POST (369-byte body)
05-11 09:28:52.970 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: --> POST http://adm-erp-tst1.adm.gov.sa:8001/webservices/rest/mobilesvc/validate_user_login/ http/1.1
05-11 09:28:52.970 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: Content-Type: application/json; charset=UTF-8
05-11 09:28:52.970 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: Content-Length: 369
05-11 09:28:52.970 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: Authorization: Basic U1lTQURNSU46aHVsNTU4ODg1OA==
05-11 09:28:52.970 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: Accept: text/html
05-11 09:28:52.970 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: {"VALIDATE_USER_LOGIN_input":{"RESTHeader":{"NLSLanguage":"AMERICAN","RespApplication":"SYSTEM_ADMINISTRATOR","SecurityGroup":"STANDARD","@xmlns":"http://xmlns.oracle.com/apps/per/soaprovider/plsql/rest/mobilesvc/header"},"@xmlns":"http://adm-erp-tst1.adm.gov.sa:8001/webservices/rest/mobilesvc/"}}
05-11 09:28:52.970 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: --> END POST (369-byte body)
05-11 09:28:53.000 19171-19211/com.ites.makkahleave.mobileerp W/EGL_emulation: eglSurfaceAttrib not implemented
05-11 09:28:53.000 19171-19211/com.ites.makkahleave.mobileerp W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xe184c1e0, error=EGL_SUCCESS
05-11 09:28:53.374 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: <-- 401 Unauthorized http://adm-erp-tst1.adm.gov.sa:8001/webservices/rest/mobilesvc/validate_user_login/ (404ms)
05-11 09:28:53.374 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: Date: Wed, 11 May 2016 13:28:53 GMT
05-11 09:28:53.374 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: WWW-Authenticate: Basic realm="__ebsisgrealm__"
05-11 09:28:53.374 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: Keep-Alive: timeout=15
05-11 09:28:53.374 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: Connection: Keep-Alive
05-11 09:28:53.374 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: Transfer-Encoding: chunked
05-11 09:28:53.374 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: Content-Type: text/html
05-11 09:28:53.374 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: OkHttp-Sent-Millis: 1462973333124
05-11 09:28:53.374 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: OkHttp-Received-Millis: 1462973333374
05-11 09:28:53.375 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: <ISGServiceFault>
05-11 09:28:53.375 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: <Code>FND_SOA_AUTHENTICATION_FAILURE</Code>
05-11 09:28:53.375 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: <Message>Invalid username or password..Could not authenticate user / token</Message>
05-11 09:28:53.375 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: <Resolution>Please pass correct user/token.</Resolution>
05-11 09:28:53.375 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: </ISGServiceFault>
05-11 09:28:53.375 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: <-- END HTTP (228-byte body)
05-11 09:28:53.375 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: <-- 401 Unauthorized http://adm-erp-tst1.adm.gov.sa:8001/webservices/rest/mobilesvc/validate_user_login/ (404ms)
05-11 09:28:53.375 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: Date: Wed, 11 May 2016 13:28:53 GMT
05-11 09:28:53.375 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: WWW-Authenticate: Basic realm="__ebsisgrealm__"
05-11 09:28:53.375 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: Keep-Alive: timeout=15
05-11 09:28:53.375 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: Connection: Keep-Alive
05-11 09:28:53.375 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: Transfer-Encoding: chunked
05-11 09:28:53.375 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: Content-Type: text/html
05-11 09:28:53.375 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: OkHttp-Sent-Millis: 1462973333124
05-11 09:28:53.375 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: OkHttp-Received-Millis: 1462973333374
05-11 09:28:53.375 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: <ISGServiceFault>
05-11 09:28:53.375 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: <Code>FND_SOA_AUTHENTICATION_FAILURE</Code>
05-11 09:28:53.375 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: <Message>Invalid username or password..Could not authenticate user / token</Message>
05-11 09:28:53.375 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: <Resolution>Please pass correct user/token.</Resolution>
05-11 09:28:53.375 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: </ISGServiceFault>
05-11 09:28:53.375 19171-19269/com.ites.makkahleave.mobileerp D/OkHttp: <-- END HTTP (228-byte body)