I am developing an Android application that can read data from a Lotus Domino database. I started creating an HTTP authentication page, and I ran into a lot of difficulties. This is my piece of code:
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 {
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);
HttpResponse response = client.execute(httppost);
HttpEntity responseEntity = response.getEntity();
if (response.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_OK){
final InputSource inputSource = new InputSource(responseEntity.getContent());
TextView res=(TextView)findViewById(R.id.result);
res.setText("Server response: "+inputSource.toString());
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Server response: org.xml.sax InputSource @ 40575700
Trying the same in the browser, I see the login page and after that the content is "mypage". I am a little confused with the correct approach and mechanism that I have to follow on Android. Any help would be greatly appreciated!
source
share