1

I have written a code to access Google API. The URL when hit from a browser gives immediate response but when hitting the same URl from Eclipse using a OkHttpClient leads to a connection time out. Have tried using various methods to hit the URL still its a connection time out every time. I even tried using HTTP instead of HTTPS but still no luck. I have no much knowledge in networking but it seems issue is due to office network since code works fine with my home network. Also I have tries setting a higher timeout value still it never connects. So please let me know what might be the probable reason and how to overcome the office proxy or whatever is creating the issue. Below is the code which I am using currently

public static String getAPIData(String finalURL) throws Exception {
    // TODO Auto-generated method stub

    OkHttpClient client = new OkHttpClient();
    Request request = new Request.Builder().url(finalURL).build();

    Response response = client.newCall(request).execute();
    return response.body().string();

}
5
  • Check this out . Commented Mar 1, 2019 at 5:01
  • stackoverflow.com/questions/5662283/… Commented Mar 1, 2019 at 5:26
  • I have no connectivity issue or network slowness at my office. Also I have already tried setting the time out still it never connects. Commented Mar 1, 2019 at 5:34
  • @Kunal stackoverflow.com/questions/54918971/… read comment may help you. Commented Mar 1, 2019 at 5:57
  • @SHAHAKASH That comment is not showing how to get the thing working. They are just assumptions of network configuration. I want to learn how to make this thing working with some steps to the procedure. Commented Mar 4, 2019 at 5:55

1 Answer 1

1

I had the same issue before, and I solved it by setting Java VM arguments. I had some proxy setting in my network, so I set the same proxy in the Java VM arguments.

Click Run -> Run Configurations -> Click Arguments tab on the right -> Write on VM arguments:
-Dhttp.proxyHost=[your proxy server] -Dhttp.proxyPort=[your proxy port]

For example, if your PC proxy's server is exmaple.proxy.com, and port is 8080, just input below in the VM arguments:
-Dhttp.proxyHost=exmaple.proxy.com -Dhttp.proxyPort=8080

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.