Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing Internet through Proxy Server

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I access internet through my java application from my home i.e. no proxy server, then I am able to get access to it.
But when I try to access internet from my office where there is a proxy server, I get a unkownhostexception and none of the java applications making using of java.net package execute.
Please help me find out the solution to this problem.
// sample code
import java.net.*;
import java.io.*;
public class SourceViewer
{
public static void main(String args[])
{
URL url;
try{
if (args.length > 0)
url = new URL(args[0]);
else
url = new URL("http://www.microsoft.com");
URLConnection uc = url.openConnection();
InputStream raw = uc.getInputStream();
InputStream buffer = new BufferedInputStream (raw);

Reader r = new InputStreamReader(buffer);
int c;
while ((c = r.read()) != -1)
{
System.out.print((char) c);
}
}
catch(MalformedURLException e)
{
System.err.println("Invalid URL");
}
catch(IOException e)
{
System.err.println(e);
}


}// main

}// class SView
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try out the following code. Replace the your_proxy stuff with your actual proxy server and port and proxy login and password. Hope this helps.
 
Sajid Niazi
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanx Dan Richardson. Your solution worked for me.
It even worked when I commented out the code that deals with username and password. Probably 'coz I had access to internet when I used a browser(setting proxies in browser).
Again a lot of thanx for helping me.
Regards
sajid niazi
[ August 17, 2002: Message edited by: Sajid Niazi ]
 
Destroy anything that stands in your way. Except this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic