0

I'm developing an application on spring boot, however I needed to integrate recaptcha for security purposes on various forms, however the connection always results in a connection timed out, I verified api and the url with postman and it goes through and returns an answer, however on Java code times run out and I get the error java.net.ConnectException: Connection timed out: connect I don't know what I'm doing wrong I use the postman code that provides on "Java OK HTTP". code is the next one.

OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
.url("https://www.google.com/recaptcha/api/siteverify?secret=XX&response=XXX")
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "f47548e1-a9e0-9065-7f76-dced294bddcb")
.build();

Response response = client.newCall(request).execute();

However I don't seem to get where the error is, can someone help me?

Ajit Soman
  • 3,926
  • 3
  • 22
  • 41
Zenoheld
  • 37
  • 1
  • 14

1 Answers1

1

You have a Connection timed out error, so we can say that:

  • since this is not an Unknown host error, you must have a DNS that gives an IPv4 or IPv6 address for www.google.com
  • since this is not a destination unreachable error, you have a route to a gateway and this gateway is a local router that has a default route.

Therefore, the timeout for connect means you have sent a TCP SYN packet to a destination, and this packet has been dropped somewhere in your local network or at the interface between your network and the Internet, in a firewall (since you have not received any ICMP/ICMPv6 packet saying something was wrong - a standard router should have sent you such an information).

The problem is with the first packet (TCP SYN), so your problem can not be relative to your addHeader() calls in your source code. Those headers are never sent, in your case, with this error.

Since www.google.fr has IPv4 and IPv6 addresses, there are two possibilities:

  • either you have a local IPv6 router that sends RA advertisments, but is not connected to the Internet with IPv6. Try this to check this case:

replace:

https://www.google.com/recaptcha/api/siteverify?secret=XX&response=XXX

by:

https://[2a00:1450:400c:c04::6a]/recaptcha/api/siteverify?secret=XX&response=XXX

If you continue to get a timeout, this means you have an IPv6 router that is badly configured.

  • or you have a firewall and need to use a proxy

replace:

https://www.google.com/recaptcha/api/siteverify?secret=XX&response=XXX

by:

https://74.125.206.104/recaptcha/api/siteverify?secret=XX&response=XXX

If you continue to get a timeout, this means you have a firewall and should use a proxy.

Alexandre Fenyo
  • 4,526
  • 1
  • 17
  • 24
  • Actually I got a timeout with last conf, but I got an unreachable with the first one, how is it possible to use a proxy ?? – Zenoheld Sep 04 '17 at 21:05
  • Since you have a timeout with last conf and unreachable with first one, you are right: you need to use a proxy. You certainly have to use a proxy with authentication (the most common case). So, read this: https://stackoverflow.com/questions/35554380/okhttpclient-proxy-authentication-how-to – Alexandre Fenyo Sep 04 '17 at 21:12
  • 1
    At the very end it did not work, but worked on my other machine, proxy was a being a pain in the ass, problem is a configuration was needed since I work inside a Virtual machine, thank you so much. – Zenoheld Sep 06 '17 at 00:09