Download a file with redirected URL?
BlitzMax Forums/BlitzMax Programming/Download a file with redirected URL?
| ||
Hi everyone! The download function I have been using for years is broken. I'd like to download files directly from Dropbox, but the original download url is redirected and I so only download the error message below: 302 Found The resource was found at https://dl.dropboxusercontent.com/u/98035398/prp/prp_stationlist.zip; you should be redirected automatically. If I change the url to "https" the download isn't possible as well. But when I copy the exact link into my browser window it works fine?!? I put up a simple example that shows the issue. Example: Const PRP_UPD_LIST:String = "prp_stationlist" Global ini_update_server:String = "http://dl.dropboxusercontent.com/u/98035398/prp/" ' <- Default URL TO UPDATE SERVER 'Global ini_update_server:String = "https://dl.dropboxusercontent.com/u/98035398/prp/" ' <- Default URL TO UPDATE SERVER If HTTPGetFile:Int(ini_update_server+PRP_UPD_LIST+".zip", PRP_UPD_LIST+".zip") = -1 Then Print "File not found!" Else Print "File downloaded!" Function HTTPGetFile:Int(url$, filePath$) Url$ = url$.Replace("http://", "http::") Local bank:TBank=LoadBank(url) If bank <> Null Then ?macos SaveBank bank,CurrentDir()+"/"+filePath$ ? ?Win32 SaveBank bank,CurrentDir()+"\"+filePath$ ? ?Linux SaveBank bank,CurrentDir()+"/"+filePath$ ? Return 1 Else Return -1 EndIf End Function Thanks in advance. Grisu |
| ||
You will have to check the response header. It contains things like "302" - redirects. In that case you just do another request to the url you read out of the former response. Think when using something like "curl" this should be done automatically. bye Ron |
| ||
Indeed, libcurl can handle redirects transparently. Aren't you already using libcurl in PRP ? |
| ||
I think this code handled redirects properly -- haven't tried it for a while! |
| ||
Well, the code above has the same issues. It doesn't download the file and "hangs" without giving a response.Server response: HTTP/1.1 302 FOUND cache-control: no-cache Content-Type: text/html; charset=utf-8 Date: Sat, 02 Aug 2014 18:03:56 GMT location: https://dl.dropboxusercontent.com/u/98035398/prp/prp_stationlist.zip pragma: no-cache Server: nginx set-cookie: flash=; Domain=dropbox.com; expires=Sat, 02 Aug 2014 18:03:56 GMT; Path=/; httponly set-cookie: bang=; Domain=dropbox.com; expires=Sat, 02 Aug 2014 18:03:56 GMT; Path=/; httponly set-cookie: uc_session=yyK0PVy4FhRj4b813QNGc5IaKIrepQP06jVPLb5SaDEKQQs8hcI1z0XkMjOQpW7N; Domain=dropboxusercontent.com; Path=/; secure; httponly Content-Length: 400 Connection: keep-alive |
| ||
@Brucey: Yes, PRP uses libcurl, but only for the multifile downloads so far. I tried one of the examples. Also with no luck. Executing:ex_05.exe success ********************************************* Timeout was reached So my guess is that I need to look for another file webspace... :/ |
| ||
So my guess is that I need to look for another file webspace There's nothing wrong with dropbox. That example works fine for me, replacing with your URL above - assuming you are using libcurlssl of course (since it is an https url, which requires SSL support). I doubt James' example support https. |
| ||
Yeah, sorry, didn't notice it was https! It works for non-https redirects though. |
| ||
Do I need both modules libcurlssl and libcurl? Is libssh2 a requirement as well? I got a "libeay32.dll" error on my system. Installed http://slproweb.com/products/Win32OpenSSL.html to get around it. - Do all users need to install the dll manually? Or will the compiled exe be enough? Is there any simple example for downloading a file with Libcurlssl? I'm fishing in the dark here. |
| ||
Do I need both modules libcurlssl and libcurl? They are the same thing - libcurlssl adds support for SSL certificates and related content. The reason that there are two modules is that SSL support adds extra requirements, such as OpenSSL which lots of people don't need for many uses of curl (like if they only want support for http and ftp, etc). Is libssh2 a requirement as well? Only if there's an import for it in the module (which there appears to be). Probably for SFTP support, which is FTP over an SSH tunnel. Do all users need to install the dll manually? It's a dll, just include it in the same dir as your exe, as you would with any other third-party DLL. Make sure you include all the required DLLs from that distribution. Windows apps look first in the local directory for DLLs. Is there any simple example for downloading a file with Libcurlssl The examples are essentially the same for both modules. There are some extra examples for libcurlssl, which show usage of SSL-related things. |