File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access to website using Java Code

 
Supraja Kannaiyan
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9214
9
Linux Mac OS X Windows
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic