So I am confused about the new URLConnection class. I would think that when using the form:
URLConnection.SendSync(method As String, URL As String, timeout As Integer) As String
… that it would return a string that contains the result/response of the request… but the code does not seem to wait for a response and instead I immediately get an empty string. The only way I can access the response is in from the ContentReceived event.
I thought the whole point (and potential problem) with SendSync is that the code waited for the response.
The documentation also seems to confirm this: “Results appear in the ContentReceived event”.
If this is true then what is the point of SendSync?
MyWindow.URLC = New URLConnection
MsgBox MyWindow.URLC.SendSync("get", "https://jsonplaceholder.typicode.com/todos/1", 30)
This doesn’t work (button.action event):
Dim uc As New URLConnection
MsgBox uc.SendSync("get", URLField.Text, 30)
Both examples are NOT working.
But when one drops a URLConnection on a Window it’s suddenly working?
Only when there is a instance dropped on the window it works, as in the examples.
I was under the impression it did work everywhere but it doesn’t seem to work under normal conditions.
[quote=417589:@James Meyer]Maybe my headers are wrong… which could be causing my request to be rejected immediately.
[/quote]
On second thought the headers are not my problem… because I am getting the expected results in the ContentReceived event… I am just not getting it in from the returned value of the SendSync method.
i’ve edited my above post.
As you notice the examples do work (nice) but they are not what we all use. It seems that making an instance manually DOESN’T work for URLConnection (but dropping an instance to a window DOES work). Well that’s odd.