While trying to diagnose an Android project issue, I ran into the following problem:
Dim conn As New URLConnection
Dim s As String = conn.SendSync("GET", "https://www.apple.com/")
Dim headers() As String
For Each header As pair In conn.ResponseHeaders
headers.Add header.Left.stringvalue + ": " + header.Right.StringValue
Next
Break
This code appears to hang at the SendSync call, but it’s hard to tell because the debugger shows the breakpoint on the next line.
I’ve tried
• Different methods (GET, POST, PUT, HEAD)
• Adding Timeouts (5, 10, 30)
I am able to get the response headers when sending asynchronously, via the HeadersReceived Event. However, I never get headers when sending synchronously.
Also, an observation: The response headers aren’t received / displayed in the order that they’re returned by the server. That shouldn’t be a problem, but it is good to know.
The content seems to come in normally when making requests to other sites, including xojo.com - and it does so whether sending asynchronously or synchronously requests.
When making a request to apple.com (either synchronously or synchronously), I can see the response content in the debugger. However, it’s only visible when choosing to see it as Binary data, or by changing the Text “View As” option to something like UTF-32.
And here’s something odd: If you look at the raw response from apple.com, you’ll see that after the response headers, there are ~40 empty lines before the “DOCTYPE” tag. I don’t know why Apple’s doing this, but I suspect that might be the cause of all this weirdness.
Interesting. On my machine, the HeadersReceived and ContentReceived events never fire when running on Android. Everything works as expected on the other platforms.
So it turns out that the content is being received. It doesn’t look like anything’s coming in (especially in the editor) because of those 40 blank lines.
My home Internet was down so I plugged my iPhone to my Mac to share the network connection. Whatever I did, the Android Emulator couldn’t process any request.
As soon as Internet (over wifi) was fixed, the Android Emulator could process HTTP requests. Could this be something similar to your experience?