aspose file tools*
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
Author

Access to website using Java Code

Supraja Kannaiyan
Ranch Hand

Joined: Mar 09, 2007
Posts: 41
Hi,

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.

Thanks,
Supraja
Ulf Dittmer
Marshal

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

What do you mean by "proxy site"?


Ping & DNS - my free Android networking tools app
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();
huc.setRequestMethod("GET");
try{
huc.connect();
}catch(Exception es){
es.printStackTrace();
System.out.println("Exception "+es.getMessage());
System.out.println("RESPONSE CODE"+huc.getResponseCode());
Thread.sleep(2000);
huc.connect();
}
BufferedReader reader = new BufferedReader(new InputStreamReader(huc.getInputStream()));

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

Joined: Oct 29, 2001
Posts: 8908
    
    8

Java Networking and Proxies


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Access to website using Java Code