wood burning stoves 2.0*
The moose likes Sockets and Internet Protocols and the fly likes  Http through Firewall/Proxy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark " Http through Firewall/Proxy" Watch " Http through Firewall/Proxy" New topic
Author

Http through Firewall/Proxy

Shamish Naharas
Greenhorn

Joined: Jul 11, 2002
Posts: 1
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
ction.java:463)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection
.java:454)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:556)
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[] )
{
try
{
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");
System.out.println("Property:"+connection.getRequestProperty("Proxy-Authorization"));

// 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 );
}
input.close();
}
catch( Exception e )
{
System.out.println( e );
e.printStackTrace();
}
}
}
Thanks again in advance to everyone who responds/helps out.
Regards,
Shamish
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Http through Firewall/Proxy
 
Similar Threads
Tomcat cant recognize "error-page" tag in web.xml
Problem in proxy settings
Why settimeout is not working?
SocketException in WSAD
how to read files from internet