Online URLConnection

If I declare a URLConnection in my code, can I get the content?

Var myConnection as new URLConnection
myConnection.send("get", "http://wwwmypage.com", time)

Can I know the content returned? Can I access somehow to the “ContentRecieved” event?

Yes, with AddHandler you need to “make” the event. See http://documentation.xojo.com/api/code_execution/addhandler.html .

1 Like

Thank you. I think I know how to do it.

myConnection will go out of scope if you use it that exact way.

make sure you have a myConnection As URLConnection property on a window, control or whatever to keep it in scope.

just use

myConnection = New URLConnection 

once you want to do a new request.

If you want it back right then and there, you can also use SendSync.

But it shouldn’t be used. https://thezaz.com/blog/urlconnectionsendsync_is_a_per

3 Likes

He didn’t say anything about siding it in a thread.

He didn’t need to. On a thread, SendSync eats performance. Off a thread, it locks the UI. So basically it always sucks.

2 Likes

Thank you all.
I’ve used SendSync sometimes and other times I used the AddHandler.
But it worked.