0

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!

Tianbing Leng
  • 560
  • 1
  • 8
  • 22

1 Answers1

0

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

Community
  • 1
  • 1
AdityaKeyal
  • 1,208
  • 8
  • 14
  • Thanks for your suggestion. However, after I added the code, still same output. `System.setProperty("my proxy address", "8080");` Did I also need user authenticator?? – Tianbing Leng Jan 07 '15 at 07:26
  • Yes.. if you are behind a company proxy. you probably also have authentication. try your domain credentials.. also ensure that your proxy port is as per your internet explorer setting – AdityaKeyal Jan 07 '15 at 09:05
  • I have finally gave up the proxy issue, actually i could move to next step. (As I used a intranet fdqn to login.) How can i do like this: redirect the link 5 times within 1s? -> I would like to increase the page hit actually. – Tianbing Leng Jan 08 '15 at 09:32
  • You could try to open parallel threads and base them on a timer.. the time will start a new thread every 12 seconds.. Just a random thought.. – AdityaKeyal Jan 08 '15 at 09:38