how to connect a site by proxy server using url
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Monday, January 5, 2004 12:00 AM

simple method to connect a site through proxy server using url

Re: how to connect a site by proxy server using url

Posted By:   Anin_Mathen  
Posted On:   Monday, January 5, 2004 09:41 AM

Try this snippet...

try
{
String proxy_internet_address = "198.34.23.87";
int proxy_internet_port = 80;
ProxyAuthenticator proxAuth = new ProxyAuthenticator("userid","pwd");
java.net.Authenticator.setDefault(proxAuth);

URL url = new URL("http://yourodmain/url");

java.util.Properties systemProperties = System.getProperties();
systemProperties.setProperty("http.proxyHost",proxy_internet_address);
systemProperties.setProperty("http.proxyPort",String.valueOf(proxy_internet_port));

HttpURLConnection aConnection = (HttpURLConnection)(url.openConnection());
aConnection.setDoInput(true);
aConnection.setDoOutput(true);
aConnection.setUseCaches(false);
aConnection.connect();

InputStreamReader insr = new InputStreamReader(aConnection.getInputStream());
br = new BufferedReader(insr);
while((textString = br.readLine())!=null){
s = s + textString;
}
br.close();
aConnection.disconnect();
} catch(Exception ex) {
ex.printStackTrace();
}


Hope this helps.


Anin
About | Sitemap | Contact