0
我想繞過Android的基本身份驗證,並陷入了這個錯誤。 請參閱下面我的代碼:MalformedChallengeException:身份驗證的挑戰是空的
HttpUriRequest request = new HttpGet(url);
String credentials = "username" + ":" + "password";
String base64EncodedCredentials = Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
request.addHeader("Authorization", "Basic " + base64EncodedCredentials);
HttpClient httpclient = new DefaultHttpClient();
try {
HttpResponse response = httpclient.execute(request);
Log.d("Login: Response", EntityUtils.toString(response.getEntity()));
} catch (IOException e) {
e.printStackTrace();
}
這是我得到的錯誤..
09-29 12:01:21.990: W/System.err(3438): org.apache.http.client.ClientProtocolException
09-29 12:01:21.990: W/System.err(3438): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:672)
09-29 12:01:21.990: W/System.err(3438): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509)
09-29 12:01:21.990: W/System.err(3438): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
09-29 12:01:21.990: W/System.err(3438): at com.accenture.emsmobile.backend.LoginAsyncTask.doInBackground(LoginAsyncTask.java:33)
09-29 12:01:22.000: W/System.err(3438): at com.accenture.emsmobile.backend.LoginAsyncTask.doInBackground(LoginAsyncTask.java:1)
09-29 12:01:22.000: W/System.err(3438): at android.os.AsyncTask$2.call(AsyncTask.java:287)
09-29 12:01:22.000: W/System.err(3438): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
09-29 12:01:22.000: W/System.err(3438): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
09-29 12:01:22.000: W/System.err(3438): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
09-29 12:01:22.000: W/System.err(3438): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
09-29 12:01:22.010: W/System.err(3438): at java.lang.Thread.run(Thread.java:841)
09-29 12:01:22.010: W/System.err(3438): Caused by: org.apache.http.auth.MalformedChallengeException: Authentication challenge is empty
09-29 12:01:22.020: W/System.err(3438): at org.apache.http.impl.auth.RFC2617Scheme.parseChallenge(RFC2617Scheme.java:72)
09-29 12:01:22.020: W/System.err(3438): at org.apache.http.impl.auth.AuthSchemeBase.processChallenge(AuthSchemeBase.java:111)
09-29 12:01:22.030: W/System.err(3438): at org.apache.http.impl.auth.BasicScheme.processChallenge(BasicScheme.java:95)
09-29 12:01:22.030: W/System.err(3438): at org.apache.http.impl.client.DefaultRequestDirector.processChallenges(DefaultRequestDirector.java:1068)
09-29 12:01:22.030: W/System.err(3438): at org.apache.http.impl.client.DefaultRequestDirector.handleResponse(DefaultRequestDirector.java:965)
09-29 12:01:22.030: W/System.err(3438): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:475)
09-29 12:01:22.030: W/System.err(3438): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:670)
09-29 12:01:22.030: W/System.err(3438): ... 10 more
請點擊此鏈接: http://stackoverflow.com/questions/3283 234/http-basic-authentication-in-java-using-httpclient – prakash 2014-09-29 04:17:48
試過這些,仍然沒有發現認證挑戰。 – user142020a 2014-09-29 04:41:43
如果用戶名和密碼正確,它正在工作,但在憑證錯誤時引發異常。 – user142020a 2014-09-29 05:13:22