Hello
As part of the development of an Android application for my business, I
have to communicate with a through a proxy with authentication server.
Here's the code I wrote:
final HttpURLConnection connection = (HttpURLConnection) new
URL(url).openConnection(new Proxy(Proxy.Type.HTTP, new
InetSocketAddress(PROXY_NAME, PROXY_PORT)));
Authenticator.setDefault(new NtlmAuthenticator(PROXY_USERNAME, PROXY_PASSWORD));
connection.setConnectTimeout(5000);
connection.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
connection.setDoInput(true);
connection.setDoOutput(true);
final int retCode = connection.getResponseCode();
System.out.println("Return code : " + retCode);
with the class
private class NtlmAuthenticator extends Authenticator {
private final String username;
private final String password;
public NtlmAuthenticator(final String username, final String password) {
super();
this.username = username;
this.password = password;
}
@Override
public PasswordAuthentication getPasswordAuthentication() {
System.out.println("Get password auth");
return (new PasswordAuthentication(username,
password.toCharArray()));
}
}
Unfortunately, I still get a response code equal to 407 and I've realized
that I never spent in the method getPasswordAuthentication
The same program works very well with a Java program not Android.
My version of Android is 4.4.4 and I have seen it used OkHttp for queries.
By debugging and entering the code of Android, I've realized that the
object contained OkHttp well my proxy configuration but not my
authenticator.
Could you help me ?
Thank you
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/205b9057-f9a5-4747-a292-445d37e549ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.