URLConnection.SendSync confusion

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?

It should return the results in the String return value (I’ve updated the text). And it does work that way for me in the example project:

Examples/Communication/URLConnection/URLConnectionGET

@James Meyer on which platform are you having those results?

Mac

On Windows it works with 32-bit and 64 bit for me.

Is the problem the same on 64-bit and 32-bit ?

Maybe my headers are wrong… which could be causing my request to be rejected immediately.

Again, I am confused about setting request headers. Should it be:

Self.RequestHeader(“Authorization”) = “MyAPIKey”

or

Self.RequestHeader(“Authorization”, “MyAPIKey” )

?

on a window make a property:

MyWindow.URLC As URLConnection

This example doesn’t work:

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.

Feedback report made:
feedback://showreport?report_id=54410

It seems you have found an bug which is reproducable.

Yes, Derk thanks for your help.

If I change the URLConnectGet example project GetButton action code to:

dim uc as new URLConnection
dim result as string
result = uc.SendSync(“GET”, “https://jsonplaceholder.typicode.com/todos/1”, 30)
beep

… and set a breakpoint at the beep… “result” is empty… but the original code works fine.

[quote=417597:@James Meyer]Yes, Derk thanks for your help.

If I change the URLConnectGet example project GetButton action code to:

dim uc as new URLConnection
dim result as string
result = uc.SendSync(“GET”, “https://jsonplaceholder.typicode.com/todos/1”, 30)
beep

… and set a breakpoint at the beep… “result” is empty… but the original code works fine.[/quote]

Well good find. Let’s hope for a quick fix