1

I'm having trouble getting a response from a http request when the phone is connected via WiFi. When it's using mobile data everything works fine. Here is the code:

doc = Jsoup.connect("https://www.facebook.com/")
      .userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
      .referrer("http://www.google.com")
      .get(); 

I get java.net.SocketTimeoutException:Read timed out exception. I have added these permissions in my manifest file:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Why is it working on mobile data and not on WiFi? (The phone has working internet access through WiFi). Thank you!

Barns
  • 4,850
  • 3
  • 17
  • 31
  • Are you able to connect through Facebook through the browser? What do you mean when you say "it's not working," are you getting an error back, is it timing out, etc? – shortstuffsushi Apr 17 '18 at 22:57
  • Yes. Through my browser I can connect to facebook, but my app stucks and freezes at the request. In debug I saw that I get java.net.SocketTimeoutException:Read timed out exception. – Andrei Nutu Apr 18 '18 at 07:20
  • If you get Read timed out exception you better look here - https://stackoverflow.com/questions/6571548/i-get-a-sockettimeoutexception-in-jsoup-read-timed-out?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – TDG Apr 18 '18 at 14:47
  • The answer in the linked question suggestions setting the timeout to infinity, which is probably not a good long term solution. However, you could try increasing it to a minute or two to see if it's just a duration issue or not. That's a good starting point. – shortstuffsushi Apr 18 '18 at 17:23

0 Answers0