我正在开发一个能够从 Lotus Domino 数据库中读取数据的 android 应用程序。我开始创建一个页面来测试 HTTP 身份验证,我遇到了很多困难。这是我的代码片段:
public void GoAuth(View v){
final String httpsURL = "http://xxx.xxx.xxx.xxx/names.nsf/mypage?openpage";
final DefaultHttpClient client = new DefaultHttpClient();
final HttpPost httppost = new HttpPost(httpsURL);
String userName = "demo";
String password = "demo";
try {
//authentication block:
final List<BasicNameValuePair> nvps = new ArrayList<BasicNameValuePair>();
nvps.add(new BasicNameValuePair("Username", userName));
nvps.add(new BasicNameValuePair("Password", password));
final UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(nvps, HTTP.UTF_8);
httppost.setEntity(p_entity);
//sending the request and retrieving the response:
HttpResponse response = client.execute(httppost);
HttpEntity responseEntity = response.getEntity();
if (response.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_OK){
//handling the response
final InputSource inputSource = new InputSource(responseEntity.getContent());
TextView res=(TextView)findViewById(R.id.result);
res.setText("Server response: "+inputSource.toString());
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
服务器响应为:org.xml.sax InputSource@40575700
在浏览器中尝试相同的操作,我看到登录页面,然后是“mypage”的内容。我对我必须在 android 上遵循的正确方法和机制有点困惑。任何帮助将不胜感激!