Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thro a proxy server

 
Guhan Ramanan
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello people!
At my place of work, my machine is connected to the Net thro a proxy server.
When I run any Internet programs using methods like
getByName(), it says host not found. How do I get to the Net using a proxy?
The sample code follows:
import java.io.*;
import java.net.*;
class InetTest
{
public static void main(String args[]) throws UnknownHostException
{
InetAddress Address = InetAddress.getLocalHost();
System.out.println(Address);
Address = InetAddress.getByName("www.hotmail.com");
System.out.println(Address);
}
}

Plz let me know
-Guhan
 
lokesh reddy
Ranch Hand
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the main method just type these two lines.
Properties prop=System.getProperties();
prop.put("http.proxyHost",<your proxy host name> );
prop.put("http.proxyPort",<your proxy port no> );
remember replace "your proxy host name" with proper host name and "your proxy port no" with proper port no.
I think this should work fine.
Loke.
 
Vim Win
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi lokesh,
I have the same setup in which I connect to a Proxy which is connected to Internet. I tried the same example given above with Properties being set. But I was not able to connect and it gave me a UnknownHostException. Can you clarify what could be the reason ??
The code is as follows :
Properties prop = System.getProperties();
prop.put("http.proxyHost","172.16.0.104");
prop.put("http.proxyPort","80");
Then I tried the Hotmail name. I couldnt get the IP.
Moreover is there anyway by which we can get the name of the host given its IP address. Say, I have to know the name of the proxy. I know the IP as 172.16.0.104. With this info, can I get the name of the Server ???
Kindly clarify.
With Advance Thanx.
JVRN.
 
Guhan Ramanan
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi JVRN
u can get the name of the server by passing the IP as a String.
btw, I tried the following code and it still doesnt work..
import java.io.*;
import java.net.*;
import java.util.*;
class InetTest
{
public static void main(String args[]) throws UnknownHostException
{
Properties prop=System.getProperties();
prop.put("http.proxyHost","PROXYSERVER");
prop.put("http.proxyPort","80");

InetAddress Address = InetAddress.getLocalHost();
System.out.println(Address);
Address = InetAddress.getByName("www.hotmail.com");
System.out.println(Address);
}
}

It displays my local host but not hotmail's IP.
I tried lower and Upper Cases with http.
My system property gets added with http.ProxyServer="PROXYSERVER" and the port also.
I am still unable to get out of the proxyserver
Plz help
-Guhan
 
Rajamohan Thangapalam
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear,

The About code for proxy work fine for the http request only not DNS for your code to work you should set the proper DNS

bye
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic