HTTP Error 407 Proxy authentication required

C

ckarunprakash

I am trying to access the url by using this code

System.setProperty("http.proxyHost", "111.88.15.108");
System.setProperty("http.proxyPort", "8002");
System.setProperty("http.proxyUser", "user");
System.setProperty("http.proxyPassword", "password");
URL oracle = new URL("http://www.google.com/");
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)

System.out.println(inputLine);
in.close();

This is working fine in my window machine but this is not working in linux machine. i am getting eror like this

Exception in thread "main" java.io.IOException: Server returned HTTP response code: 407 for URL: http://www.google.com/ at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) at com.yahoo.Connection.main(Connection.java:31)

Even proxy settings are correct and i tried like this also

java -Dhttp.proxyHost="111.88.15.108" -Dhttp.proxyPort="8002" -Dhttp.proxyUser="user" -Dhttp.proxyPassword="password" -jar yahoo_test3.jar

But Same Error and i tried to set the export http_proxy= in /etc/profile but no use

Any idea where it is going wrong.
 
R

Real

(e-mail address removed) wrote in
I am trying to access the url by using this code

System.setProperty("http.proxyHost", "111.88.15.108");
System.setProperty("http.proxyPort", "8002");
System.setProperty("http.proxyUser", "user");
System.setProperty("http.proxyPassword", "password");
URL oracle = new URL("http://www.google.com/");
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)

System.out.println(inputLine);
in.close();

This is working fine in my window machine but this is not working in
linux machine. i am getting eror like this

Exception in thread "main" java.io.IOException: Server returned
HTTP response code: 407 for URL: http://www.google.com/ at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown
Source) at com.yahoo.Connection.main(Connection.java:31)

I believe you you need to use a java.net.Authenticator, something like

// PROXY
System.setProperty("http.proxyHost","proxy.mydomain.local") ;
System.setProperty("http.proxyPort", "80") ;

Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication
("mydomain\\username","password".toCharArray());
}});

Bye.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top