I designed an Application which uses a web view. My Application has to hit the client’s site when opened. So, I need to make an Http Connection which should take username & password for validating and to catch the response from the server and load the content using that response. I have been trying to do but unable to figure it out. Please help me in this issue. Please explain with some code.
This is what Im trying to make an Http connection but it is throwing 401 response code. I think the problem is, it is not taking the Credentials im entering in the encoder.
HttpConnection httpConn=null;
DataInputStream dis=null;
DataOutputStream dos = null;
URLEncodedPostData encPostData = new URLEncodedPostData(null, false);
encPostData.append("username", PasswordPopupScreen._response2);
encPostData.append("password", PasswordPopupScreen._response3);
try {
httpConn=(HttpConnection)Connector.open("myclient's siteURL");
httpConn.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_TYPE,
HttpProtocolConstants.CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED);
httpConn.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_LENGTH,
String.valueOf(encPostData.getBytes().length));
dos=httpConn.openDataOutputStream();
dos.write(encPostData.getBytes());
if(httpConn.getResponseCode()==HttpConnection.HTTP_OK)
{
//Dialog.alert("Success");
System.out.println("Success");
}
else
{
// Dialog.alert("failed");
System.out.println("failed");
}
} catch (IOException e) {
e.printStackTrace();
}
why the response is getting as 401? It means as Unauthorized access but im authorized to view my client's site. As of my Knowledge the problem is, the request is not appending the Username and Password. Please provide me help to appedn the credentials with the request.My client's server takes NTLM authentication.