Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #24470

Re: HTTP Error 407 Proxy authentication required

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-in-01.newsfeed.easynews.com!easynews!core-easynews-01!easynews.com!en-nntp-16.dc1.easynews.com.POSTED!not-for-mail
Newsgroups comp.lang.java.programmer
Subject Re: HTTP Error 407 Proxy authentication required
From Real <none@none.com>
References <89a83364-b61c-4e41-8d04-9edd021a06d3@googlegroups.com>
Message-ID <XnsA1E45076B893foo@127.0.0.1> (permalink)
User-Agent Xnews/2009.05.01
Lines 46
X-Complaints-To abuse@easynews.com
Organization EasyNews, UseNet made Easy!
X-Complaints-Info Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date Wed, 19 Jun 2013 11:54:39 GMT
X-Received-Bytes 2433
Xref csiph.com comp.lang.java.programmer:24470

Show key headers only | View raw


ckarunprakash@gmail.com wrote in
news:89a83364-b61c-4e41-8d04-9edd021a06d3@googlegroups.com: 

> 
> 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.
-- 
Real Gagnon  from  Quebec, Canada
* Java, Javascript, VBScript or PowerBuilder snippets
* http://rgagnon.com/howto.html
* http://rgagnon.com/bigindex.html

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

HTTP Error 407 Proxy authentication required ckarunprakash@gmail.com - 2013-06-18 22:16 -0700
  Re: HTTP Error 407 Proxy authentication required Real <none@none.com> - 2013-06-19 11:54 +0000

csiph-web