我正在製作一個android應用程序,它使用編碼的JSON從網頁中檢索數據。在我進入網頁瀏覽器的頁面時,它要求我輸入我的用戶名和密碼進行服務器身份驗證。我如何做到這一點,當我做一個httpPost;它會發送一個用戶名和密碼,所以我可以訪問該頁面。Android httpClient服務器身份驗證
它的這種身份認證http://www.wpwhitesecurity.com/wp-content/uploads/2012/08/web-server-authentication-dialogue-box.png
的我該怎麼辦呢?這裏是我的代碼:
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = null;
try {
httpResponse = httpClient.execute(httpPost);
} catch (ClientProtocolException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
HttpEntity httpEntity = httpResponse.getEntity();
try {
is = httpEntity.getContent();
} catch (IllegalStateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
你想用戶名和密碼到服務器與url..isn't它? –
它的這種服務器用戶名和通過http://www.wpwhitesecurity.com/wp-content/uploads/2012/08/web-server-authentication-dialogue-box.png –