Possible bug in URLConnection

I attempt to retrieve data from a URLConnection using the get command. When the ContentReceived Event is triggered, content as string is empty for a number of URL addresses.

Curiously, this is the case when I run my code under Xojo 2024 Release 4.1. However, when the same code is run under Xojo Release 1 or older, content is not empty. See sample project.

It does not matter if .followredirects is true or false, which appears to be one change in release 4.1.

URLConnectionTester.xojo_binary_project.zip (7.8 KB)

I should add the running under Release 4.1, content is always empty. Running under Release 1, is a bit intermittent, sometimes with content and sometimes not.

i got an answer at windows 11.
you should also add the error event.
and useful message output in the first line of a event System.DebugLog CurrentMethodName

If I run your demo, what should I see/not see?

I get a lot of HTML when I click ā€˜Get Responseā€™

I get same as @AlbertoD

Windows 10 x64 and Xojo 2024 4.1

The text area displays what is returned in contents when a URLConnection ContentReceived is triggered. When contents is not empty the text area is filled with the data returned by the URL. When contents is empty (i.e., contents=ā€œā€), the text area is empty. Under Release 4.1, content is always empty. Under Release 1, I often see that contents is not empty and I am receiving data.

I am running on a Mac OS 11.7.10

Iā€™m running macOS 13.7.2

Interesting that using Curl I get ā€˜nothingā€™, then if I use

curl -I https://cnbc.com/quotes/FGRIX

to pull the headers, I get HTTP/2 503 for the first line.

Can you use curl and see if you get something or at least the headers?
My guess is that the site is doing some filtering on your requests.

Edit: curl with https://www.cnbc.com/quotes/AAPL I get a response.

Hi @Tyrone_Daulton

Iā€™m not sure if youā€™re hoping to solve this problem just with the aid of forum members, or to have Xojo engineers looking into it.

If you want Xojo to look into this problem officially, you need to create an Issue. Describe the unexpected behaviour best you can, include your Xojo versions and OS version and your sample project.

Otherwise, it is unpredictable if and when a Xojo engineer may look at your post here.

I hope that helps.

Playing a little bit with Curl, looks like CNBC sometimes send a redirect (301) but not always (thatā€™s why AAPL answered for me).

And sometimes the redirect takes longer.

Could be that Xojo is no longer waiting much time for redirect (compared with older versions), so you get sometimes response with older Xojo and now is always empty?

As Scott said, create an Issue for Xojo staff to review.

I tested on macOS 15.2 with Xojo 2024r4.1. I always get a response when FollowRedirects = True, but never when FollowRedirects = False. This is likely due to the source redirecting the request with HTTP status code 301. There are some instances where it seems the server takes more than two seconds to respond, but I always get a response.

1 Like

I did some tests and once I was able to count to 6 before the TextArea showed the information.

Could internet speed affect in this case? Something like more than X seconds for response and URLConnection just not show anything.

Not sure if OP waited for several seconds (as other stocks respond almost instantly).

Sure. Among many other factors.

  • Connection initiated
  • Server processes connection
  • Send back a 301 in headers
  • URLConnection processes header with 301 to get redirect URL
  • URLConnection initiates new connection to redirected URL
  • Server handles the request and returns the data
  • URLConnection processes new headers and data
1 Like