Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How to program with proxy

Reply
Thread Tools

How to program with proxy

 
 
moonhk
Guest
Posts: n/a
 
      08-11-2006
Below program worked before. How to program with proxy with input User
name and password ?


import java.util.*;
import java.io.*;
import java.net.*;

public class eproxy_tofile {
public static void main(String[] args) {
Properties prop = System.getProperties();
prop.put("http.proxyHost","xx.xx.40.20");

prop.put("http.proxyPort","8081");
try {
String Addr = "http://www.new-alliance.com/Naam_NAV.htm";

URL yahoo = new URL(Addr);
System.out.println("Conneting ... " + Addr);

BufferedReader in = new BufferedReader(new InputStreamReader
(yahoo.openStream()));

String inputLine;
while ((inputLine = in.readLine()) !=null)
System.out.println(inputLine);
in.close();
}
catch (Exception exc) {
exc.printStackTrace();


}

}

}

 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      08-12-2006
moonhk wrote:
> Below program worked before. How to program with proxy with input User
> name and password ?


Socks ?

Arne
 
Reply With Quote
 
 
 
 
moonhk
Guest
Posts: n/a
 
      08-12-2006

Arne Vajh°j wrote:
> moonhk wrote:
> > Below program worked before. How to program with proxy with input User
> > name and password ?

>
> Socks ?
>
> Arne


I want daily or weekly download the contents of above site. Our Company
using proxy. So need input proxy user id and password.

 
Reply With Quote
 
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      08-13-2006
moonhk wrote:
> Arne Vajh°j wrote:
>> moonhk wrote:
>>> Below program worked before. How to program with proxy with input User
>>> name and password ?

>> Socks ?

>
> I want daily or weekly download the contents of above site. Our Company
> using proxy. So need input proxy user id and password.


I ask again: are you using socks ?

Arne
 
Reply With Quote
 
EJP
Guest
Posts: n/a
 
      08-13-2006
moonhk wrote:

> I want daily or weekly download the contents of above site. Our Company
> using proxy. So need input proxy user id and password.


Java.net.Authenticator
 
Reply With Quote
 
moonhk
Guest
Posts: n/a
 
      08-13-2006

Arne Vajh°j wrote:
> moonhk wrote:
> > Arne Vajh°j wrote:
> >> moonhk wrote:
> >>> Below program worked before. How to program with proxy with input User
> >>> name and password ?
> >> Socks ?

> >
> > I want daily or weekly download the contents of above site. Our Company
> > using proxy. So need input proxy user id and password.

>
> I ask again: are you using socks ?
>
> Arne


Sorry , What is socks ?

 
Reply With Quote
 
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      08-13-2006
moonhk wrote:
> Sorry , What is socks ?


That is a protocol that allows username/password
for a proxy server.

Which I do not think an ordinary HTTP proxy does.

But we can change the question: how do you
configure your browser to go out through that
firewall ? And how does the browser get the
username/password ?

Arne

 
Reply With Quote
 
moonhk
Guest
Posts: n/a
 
      08-14-2006

Arne Vajh°j wrote:
> moonhk wrote:
> > Sorry , What is socks ?

>
> That is a protocol that allows username/password
> for a proxy server.
>
> Which I do not think an ordinary HTTP proxy does.
>
> But we can change the question: how do you
> configure your browser to go out through that
> firewall ? And how does the browser get the
> username/password ?
>
> Arne

Checked with our Administrator, it is proxy server setting. Need to
input username/password in Browser.

 
Reply With Quote
 
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      08-14-2006
moonhk wrote:
> Checked with our Administrator, it is proxy server setting. Need to
> input username/password in Browser.


BASIC authentication ? (popup in browser ?)

Try with:

Authenticator.setDefault(new MyAuthenticator());

where:

class MyAuthenticator extends Authenticator {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("xxxx", "xxxx".toCharArray());
}
}

but I think it is a bit unusual to use HTTP BASIC authentication
with a proxy server.

Arne
 
Reply With Quote
 
moonhk
Guest
Posts: n/a
 
      08-14-2006

Arne Vajh°j wrote:
> moonhk wrote:
> > Checked with our Administrator, it is proxy server setting. Need to
> > input username/password in Browser.

>
> BASIC authentication ? (popup in browser ?)
>
> Try with:
>
> Authenticator.setDefault(new MyAuthenticator());
>
> where:
>
> class MyAuthenticator extends Authenticator {
> protected PasswordAuthentication getPasswordAuthentication() {
> return new PasswordAuthentication("xxxx", "xxxx".toCharArray());
> }
> }
>
> but I think it is a bit unusual to use HTTP BASIC authentication
> with a proxy server.
>
> Arne


try. But not work. At home below java coding is worked.

C:\Example\javaux\net>java eproxy_tofile
Conneting ... http://www.new-alliance.com/Naam_NAV.htm
java.io.IOException: Server returned HTTP response code: 500 for URL:
http://www.new-alliance.com/Naam_NAV.htm
at
sun.net.http://www.protocol.http.HttpURLConn...ction.java:800)
at java.net.URL.openStream(URL.java:913)
at eproxy_tofile.main(eproxy_tofile.java:53)

C:\Example\javaux\net>



/*

eproxy_tofile.java
2006/08/14 eric.leung


Environment variable set to
* CLASSPATH=c:\j2sdk1.4.1_01\lib\classes.zip;c:\exam ple;.
*
*/

import java.util.Properties;
import java.io.*;
import java.net.*;
import java.net.Authenticator;

public class eproxy_tofile {
public static void main(String[] args) {
Properties systemSettings = System.getProperties();



class MyAuthenticator extends Authenticator {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("xxx", "xxx".toCharArray());
}

}
// String host,port,userid,passwd;



systemSettings.put("proxySet","true");
systemSettings.put("http.proxyHost",host);
systemSettings.put("http.proxyPort",port);

// System.setProperty("https.proxyUserName",userid);
// System.setProperty("https.proxyPassword",passwd);

System.setProperties(systemSettings);

Authenticator.setDefault(new MyAuthenticator());


try {

String Addr = "http://www.new-alliance.com/Naam_NAV.htm";

URL yahoo = new URL(Addr);
System.out.println("Conneting ... " + Addr);

BufferedReader in = new BufferedReader(new InputStreamReader
(yahoo.openStream()));

String inputLine;
while ((inputLine = in.readLine()) !=null)
System.out.println(inputLine);
in.close();

}
catch (Exception exc) {
exc.printStackTrace();


}

}

}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Facebook Proxy | MySpace Proxy 35085675@qq.com Java 0 08-14-2007 06:35 AM
Inbound Proxy and Outbound Proxy chellappa VOIP 0 04-07-2006 10:58 AM
Press Release: Scalable SIP Proxy and RTP Media Proxy for NAT traversal sales@lanscapecorp.com VOIP 1 01-23-2006 06:32 PM
Help to set up tomcat 4.1.27 behind socks proxy to access database outside the proxy vidy5300 Java 0 06-07-2004 02:23 PM



Advertisments