In a desktop application that have a Button and a TextField:
in the button, I pass an URL variable (String) to URLConnection to download a file.
After I add a TextField and pass TextField1.Text to URLConnection, nothing is downloaded.
When I use the same string in code… it works !
I do not understand what happens (no special character; only a…z and %é0 for spaces; per original URL).
Even when I copy TextField1.Text to Firefox, the file is downloaded.
Asking for a project is asking for the whole project: the only code is in a button, some lines only;
Asking for a project is for you to create a simple/small/new project with only the textfield, button and URLConnection code, so others can see your code in action and give you exact information.
Have you breakpointed the debugger and examined the binary content of the string being passed to URLconnection? TextField accepts line endings, and users have a habit of hitting Enter or Return after entering text, so maybe you are passing a line ending. Try using TextField1.Text.Trim.
Thatis what I usually do when I read file names from macOS, but in that case …
I copied an URL (as text) and paste it in both the TextField and the code Editor button:
in one case (Paste in the Code Editor), the file is downloaded,
in the other case (Paste in TextField) it is not downloaded.
BTW: this is a typo, the original line (without the TextField) used theURL. Of course if I mismatch variable it will never work at all (in the two cases)…
LBN: I run the project with final changes (*) and nothing happened… so I drink a glass of fresh water and come back to see an OS dialog asking for write permission (!)…
(*): I select a “folder” path, then in a loop, I add the pdf file name to the string and download that. Worked fine for many folders, but some. Each time I can’t, I check the path for some files for that folder and if rejected, I go to the next folder (a folder in this case holds a year as digits - 1940 for example - and the first three letters for the month - Jan, Feb, etc. - ).
The HTTPStatusCode is 0.
BUT: Request url is not well-formed.
The url is: https://fultonhistory.com/Newspapers 23/Freeport NY Daily Review/Freeport NY Daily Review 1942 Jan/Freeport NY Daily Review 1942 Jan - 0011.pdf
Download fine with FireFox. I copy the url from the variable passed with “GET”, in the debuger…
In fact, some browsers will do the URL Encoding for you - if you paste a URL containing characters that need to be encoded (such as spaces, etc.) it will auto-encode it for you.
In other words, pasting a URL into a browser is not a valid way to ensure your URL will work with URLConnection.
For example, with Safari, what happens if you paste or type various strings into the search field?
example.com/foo bar gets treated as a Google search.
https://example.com/foo bar will be automatically URL encoded into https://example.com/foo%20bar