Here's the problem, I would like to write a Java program to increase the page hit for specific URL. And currently I just surfed in the Internet and get some basic program to do the testing. However, I even couldn't get the program running... Below is my program and related output.
Eclipse, Java program:
URL url = new URL("http://www.baidu.com");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
int code = connection.getResponseCode();
System.out.println("Response code of the object is " + code);
if (code == 200) {
System.out.println("OK");
}
Below is the output:
Exception in thread "main" java.net.ConnectException: Connection timed out: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:383) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:245) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:232) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:377) at java.net.Socket.connect(Socket.java:539) at java.net.Socket.connect(Socket.java:488) at sun.net.NetworkClient.doConnect(NetworkClient.java:175) at sun.net.www.http.HttpClient.openServer(HttpClient.java:407) at sun.net.www.http.HttpClient.openServer(HttpClient.java:542) at sun.net.www.http.HttpClient.(HttpClient.java:246) at sun.net.www.http.HttpClient.New(HttpClient.java:319) at sun.net.www.http.HttpClient.New(HttpClient.java:336) at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:980) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:921) at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:846) at HttpRedirectExample2.main(HttpRedirectExample2.java:14)
I have searched many resources, and some of the suggestion is the firewall issue. However, i don't think my computer with this issue as I have succeed to write a program to open a IE browser and redirect to Google.
Is anyone help me to solve this problem?
Current step, I am wondering whether is my proxy issue as I work for an company and the network is using in a proxy.
And I am also welcome if you could provide any suggestion. Thanks in advance!
You are correct. It is a proxy issue. Configure you proxy using the solution given here: I am trying to get location information from ip address in JAVA but I am getting a java.net.SocketException: Connection reset error