I'm using in my android application the HttpURLConnection through a proxy where an authentication is needed. Here is my code and I will explain you after my problem.
HttpURLConnection connection = null;
int responseCode = -1;
try {
connection = (HttpURLConnection) myUrl.openConnection();
connection.setInstanceFollowRedirects(false);
connection.setConnectTimeout(DEFAULT_TIMEOUT);
connection.setReadTimeout(DEFAULT_TIMEOUT);
responseCode = connection.getResponseCode();
System.out.println("ResponseCode = " + responseCode);
} catch (IOException e) {
System.out.println("Exception : " + e.getMessage());
}
My problem is that I get an exception on the getResponseCode() method which has the following message : Failed to authenticate with proxy.
Usually, this specific error has an http error code : 407. But here I just got an exception but not a response code with the 407 value.
I have the solution to apply the login and password to connect to the proxy, but I want to apply this solution only in the case there is a 407 error (and not each time I catch an exception).
Any idea will be appreciated. Thanks.