I’m updating some old code: to check an internet connection I used to use this snippet (posted years ago by Michael Bujardet):
Dim http As New HTTPSocket
http.yield = True
dim ih as InternetHeaders = (http.GetHeaders(“https://www.apple.com”, 1))
return (ih <> nil)
The code never fails in its response. Nevertheless I thought of replacing the deprecated HTTPSocket with URLConnection. URLConnection does not accept some of the above parameters, so I concocted the snippet below.
Now, when there is no connection, I get FALSE; yet even when I know that I do have a connection, sometimes I get False (even increasing the yeld time from 1 to 5 or more).
So I think the code actually needs improvements.
Suggestions welcome.
testConnection.xojo_binary_project.zip (4.5 KB)
Since I noticed that when there is no connection I get an exception, after initialising content I go straight to Return TRUE.
Var urlConn As New URLConnection
Var content As String = URLConn.SendSync(“GET”, “https://www.apple.com”, 1)
//Return content <> “”
Return true
Exception
return false
20 posts - 7 participants