• Post Reply Bookmark Topic Watch Topic
  • New Topic

Http through Firewall/Proxy  RSS feed

Shamish Naharas
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,
I'm trying to access our Internet Application. Our company has a firewall which we have to cross in order to access the net. I have this program which should access the internet and get the html page from it. However I get this exception:
java.net.UnknownHostException: www.yahoo.com
java.net.UnknownHostException: www.yahoo.com
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:143)
at java.net.Socket.connect(Socket.java:425)
at java.net.Socket.connect(Socket.java:375)
at sun.net.NetworkClient.doConnect(NetworkClient.java:139)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:366)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:582)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:292)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:253)
at sun.net.www.http.HttpClient.New(HttpClient.java:321)
at sun.net.www.http.HttpClient.New(HttpClient.java:306)
at sun.net.www.http.HttpClient.New(HttpClient.java:301)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConne
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
at ProxyTest.main(ProxyTest.java:82)
I am passing my login/Password information as well as setting the User Agent informatin still my program is not able to go past the Firewall.
I have another program in C# which uses .net and somehow it went past the firewall in the first try. This program is pretty much doing whatever I am doing in my java program but java program doen't work. Just for reference I am attaching the code piece from C# code too. Here it is:

string strFormData = "j_username=boston&j_password=anton&submit=login";
WebProxy Proxy = new WebProxy("internet",443);
Proxy.Credentials = new NetworkCredential(firewalllogin,firewallpass);

HttpWebRequest Request = (HttpWebRequest)HttpWebRequest.Create("https://www.hkkkk.com");
Request.Proxy = Proxy;
Request.PreAuthenticate = true;
Request.UserAgent = @"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0 ";
Request.Timeout = 100000;
Request.Method = "POST";
Request.ContentLength = strFormData.Length;
Request.ContentType = "application/x-www-form-urlencoded";
StreamWriter Writer = null;

Any help/pointer as to why my java code does not work would be greatly appreciated. Thanks in advance.

Below is my Java code:
import java.util.Properties;
import java.util.Date;
import java.net.URL;
import java.net.URLEncoder;
import java.net.HttpURLConnection;
import java.net.URLConnection;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.*;

public class MyProxy
public static void main( String argv[] )
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);

// Enable the properties used for proxy support
System.getProperties().put( "proxySet", "true" );
System.getProperties().put( "ProxyHost", "internet" );
System.getProperties().put( "proxyPort", "443" );
// URL
URL url = new URL(argv[0]);
URLConnection connection = url.openConnection();
System.out.println("Got Connection !!!");
String password = "mylogin:mypassword";
// base64 encode the password.
String encoded = new sun.misc.BASE64Encoder().encode(password.getBytes());
// Set up the connection so it knows you are sending
// proxy user information
connection.setRequestProperty ("Authorization", "Basic " + encoded);
System.out.println("setting proxy property ...");
connection.setRequestProperty("Proxy-Connection:"," Keep-Alive");
connection.setRequestProperty("User-Agent"," Mozilla/4.0 (compatible; MSIE 6.0; Windows NT; DigExt)");
connection.setRequestProperty("Timeout", "100000");

// Set up the connection so you can do read and writes
connection.setDoInput( true );
connection.setDoOutput( true );
DataInputStream input = new DataInputStream(
connection.getInputStream() );
// read in each character until end-of-stream is detected
System.out.println("Reading data ...");
for( int c = input.read(); c != -1; c = input.read() )
System.out.print( (char)c );
catch( Exception e )
System.out.println( e );
Thanks again in advance to everyone who responds/helps out.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!