jQuery in Action, 3rd edition
The moose likes Sockets and Internet Protocols and the fly likes Access to website using Java Code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Access to website using Java Code" Watch "Access to website using Java Code" New topic

Access to website using Java Code

Supraja Kannaiyan
Ranch Hand

Joined: Mar 09, 2007
Posts: 41

I am trying to access website using Java code.But i am getting SocketException. Is there anyway to bypass the proxy site and get access to the website.

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42958
What is the exception? Post the full stack trace, and the code that's causing it.

What do you mean by "proxy site"?
Supraja Kannaiyan
Ranch Hand

Joined: Mar 09, 2007
Posts: 41
Exception java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.Socket.connect(Socket.java:507)
at java.net.Socket.connect(Socket.java:457)
at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:365)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:477)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:214)
at sun.net.www.http.HttpClient.New(HttpClient.java:287)
at sun.net.www.http.HttpClient.New(HttpClient.java:299)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:792)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:744)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:669)
at com.aig.ebusiness.webgovernance.validation.getXML.main(getXML.java:20)

Source Code:

import java.net.HttpURLConnection;
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class getXML
public static void main(String args[])
URL ourURL=null;
HttpURLConnection huc = null;
try {
ourURL = new URL("http://www.dnstools.com");
huc = (HttpURLConnection)ourURL.openConnection();
}catch(Exception es){
System.out.println("Exception "+es.getMessage());
System.out.println("RESPONSE CODE"+huc.getResponseCode());
BufferedReader reader = new BufferedReader(new InputStreamReader(huc.getInputStream()));

String line = null;
while ((line = reader.readLine()) != null) {
catch(IOException ioe)
catch(Exception e)
System.err.println("General Exception " + e);
Joe Ess

Joined: Oct 29, 2001
Posts: 9137

Java Networking and Proxies

[How To Ask Questions On JavaRanch]
Have you checked out Aspose?
subject: Access to website using Java Code
It's not a secret anymore!