FileDownloader: URLConnection fails, HTTPSecureSocket works

The FileDownloader example app used to use HTTPConnection, now uses URLConnection. I recently needed to download a lot of small files and opened this project to modify for my needs. Using URLConnection, it did not work, always returned an HTTP 405 (not 401) Error, no matter what I tried (headers, etc.). So I opened the older version using HTTPSocket, updated it to use HTTPSecureSocket instead, and … that worked. Of course I had already wasted an hour and a half on the URLConnection version. Since nothing crashed, there is no bug to report. It just doesn’t work properly.

URLConnection is supposed to be the “modern replacement” for HTTPSocket and HTTPSecureSocket, which are deprecated, but the old sockets work, and the replacement doesn’t. At least not reliably. It lacks adequate control of properties and has almost no documentation. Unfortunately that seems to be a trend with replacement objects.

That said, I applaud the Xojo team for all the great work they do, and I’m extremely grateful for this fantastic tool which helps me make my living. I continue to support it. I hope problems like this will get better.

Happy New Year everyone.

HTTP 401 - Unauthorized
I can’t imagine that’s the socket’s fault unless you’re providing credentials.

Sorry, it was a 405 error, not 401.

Okay so let’s work out the issue :slight_smile:

405 is Method Not Allowed, what method were you passing (this is the first string param) for URLConnection and which function were you using with HTTPSocket?

It’s a Xojo example project. It doesn’t work. What is there to work out? Pass a valid URL and the file should download. Open the path in a browser and it downloads. Open it with the old FileDownloader and it downloads. Open it with the new one and it returns 405. Add headers for the MIME type and it changes nothing. Try changing every available property of the URLConnection and nothing changes, you continue to get the 405 error. I’m posting the problem, someone else can fix it. Sorry if that wasn’t clear, I’m really not interested in spending more time on it.

I just tested the example project with a file on my server and had no issues. I don’t work for Xojo so if you’re just going to pout I can’t help.

Of course not, the server error was “Method Not Allowed” so the method you’re using is wrong. This isn’t a guessing game, which is why I asked the question I asked.

It’s your problem to fix. The Xojo/Example Projects/Internet/URLConnection/FileDownloader.xojo_binary_project works fine.

Download this file using the current example project FileDowloader:

The server is rejecting the request with HTTP status code 406 not acceptable. This is a server directive, and not a Xojo problem. You would need to check the server logs to know more.

1 Like

Or you could download the file using the old example project, which works.

“not a Xojo problem” … what a joke.

It appears to use GET, assuming I’m looking at the right example:

Example Projects/Communication/Internet/URLConnection/Downloader.xojo_binary_project

1 Like

Yeah the answer to my question was “I didn’t change the sample project” I guess.

I kept debugging and discovered the reason, but Aaron indicated privately that they were only posting the problem and not looking for the solution.



I was looking into URLconnection recently, IIRC I was trying to figure out how to effect authorisation to gmail using OAUTH2. People have posted about this but all use the old HTTPSocket stuff. When I looked at URLconnection it seemed to me that half the methods were missing so I couldn’t figure out how to adapt it. Anyway then more immediate concerns and Christmas intervened so I’ve abandoned that for the moment.

Oauth is a little different than what’s going on here. The server is configured to respond in this way to these requests. Everything is operational here.

I know some folks are using a plugin to handle oauth. If you have specific questions or problems with the oauth procedure you might want to start your own thread for the community to debug :slight_smile:

Yeah, that’s for when I get back to it.