我正在制作一个 android 应用程序,它从带有编码 JSON 的网页中检索数据。当我在网络浏览器中访问该页面时,它要求我进行服务器身份验证,我在其中输入我的用户名和密码。当我做一个 httpPost 时,我是怎么做到的;它将发送一个用户名和密码,以便我可以访问该页面。
它的这种身份验证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();
}