Android: Ntlm Authentication, Ksoap, And Persistent Connections
After working with iOS and dealing with auth challenges without much of a learning curve, I've found that Windows Authentication is much more complicated of a process in Java/Andro
Solution 1:
I was also struggling about windows authentication from Android. I found android-ntlm-master on https://github.com/masconsult/android-ntlm. Add this class as library in your project.
Change is in NtlmTransport.java class.I made change in call method of NtlmTransport class =>
public List call(String soapAction, SoapEnvelope envelope,
List headers, File outputFile)throws IOException, XmlPullParserException {
HttpResponseresp=null;
try {
//setupNtlm(urlString, user, password); DefaultHttpClienthttpclient=newDefaultHttpClient();
httpclient.getAuthSchemes().register("ntlm", newNTLMSchemeFactory());
httpclient.getCredentialsProvider().setCredentials(
newAuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
newNTCredentials(user, password, "", "")
);
HttpPosthttpget=newHttpPost(urlString);
httpget.addHeader("soapaction", soapAction);
httpget.addHeader("Content-Type", "text/xml; charset=utf-8");
byte[] requestData = null;
try {
requestData = createRequestData(envelope);
} catch (IOException iOException) {
}
ByteArrayEntitybyteArrayEntity=newByteArrayEntity(requestData);
httpget.setEntity(byteArrayEntity);
resp = httpclient.execute(httpget);
if(resp == null) {
System.out.println("Response is null");
}
HttpEntityrespEntity= resp.getEntity();
InputStreamis= respEntity.getContent();
if(is == null) {
System.out.println("InputStream is null");
}
parseResponse(envelope, is);
} catch (Exception ex) {
// ex.printStackTrace();
}
if (resp != null) {
return Arrays.asList(resp.getAllHeaders());
} else {
returnnull;
}
}
And below is the code how I make call:
SoapObjectrequest=newSoapObject(NAMESPACE, PRODUCT_DETAILS_METHOD_NAME);
request.addProperty("ListingID", Integer.parseInt(Product_ID));
NtlmTransporthttpTransport=newNtlmTransport();
httpTransport.setCredentials(URL, USERNAME, PASSWORD, "","");
SoapSerializationEnvelopeenvelope=newSoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.implicitTypes = true;
envelope.setOutputSoapObject(request);
httpTransport.call(PRODUCT_DETAILS_SOAP_ACTION, envelope);
SoapObjectresponse= (SoapObject) envelope.getResponse();
It worked for me.
More you can find here: https://suhas1989.wordpress.com/2015/01/28/ntlm-authentication-in-android/
Post a Comment for "Android: Ntlm Authentication, Ksoap, And Persistent Connections"