libURLDownloadToFile follow php redirect?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
cborn
Posts: 66
Joined: Fri Dec 15, 2006 11:35 pm

libURLDownloadToFile follow php redirect?

Post by cborn » Tue Oct 26, 2010 9:59 pm

I'm using Rev/LiveCode to create an applet that is embedded into the pages of the course management system at our school. The CMS is Moodle, which is written in PHP. All links to media files are run through a file.php file, so a link to a file would be https://mymoodlehost.edu/file.php/PathToActualFile

I'm trying to use libURLDownloadToFile to get one of these files and pull it into the applet, but I only get an empty file (0KB). Is it the case that this command cannot follow the redirects in the file.php? Is there a way to make it do that? :?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: libURLDownloadToFile follow php redirect?

Post by FourthWorld » Tue Oct 26, 2010 10:10 pm

libURLDownloadToFile is an FTP command, but the protocol in the URL you're using is HTTP.

Have you considered just using "get" and then writing what you get to a file? e.g.:

get url "https://mymoodlehost.edu/file.php/PathToActualFile"
put it into url ("file:"& tMyLocalFile)
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

cborn
Posts: 66
Joined: Fri Dec 15, 2006 11:35 pm

Re: libURLDownloadToFile follow php redirect?

Post by cborn » Tue Oct 26, 2010 10:18 pm

libURLDownloadToFile also speaks HTTP and HTTPS, according to the dictionary. I was able to use it from another static HTTP address without any problem whatsoever.

I did try what you suggested, and that also failed.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: libURLDownloadToFile follow php redirect?

Post by FourthWorld » Wed Oct 27, 2010 12:22 am

The URL works well in your browser?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

cborn
Posts: 66
Joined: Fri Dec 15, 2006 11:35 pm

Re: libURLDownloadToFile follow php redirect?

Post by cborn » Wed Oct 27, 2010 2:15 pm

Yes, it does, as long as I'm logged into the course management system in that browser. The file downloads without a hitch in that case. It's for that reason that i suspect the problem is more in the way Rev is trying to call the file and less to do with permissions of the server or CMS itself.

FWIW, I'm using Rev Enterprise 4.0.0 Build 950. I want to move to LiveCode, but cannot realistically do so until they release the revweb plugins compatible with that version.

Thanks for thinking about this, I very much appreciate the assistance. Please let me know if you have any other ideas on how to work around this. :D

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: libURLDownloadToFile follow php redirect?

Post by FourthWorld » Wed Oct 27, 2010 5:09 pm

cborn wrote:Yes, it does, as long as I'm logged into the course management system in that browser. The file downloads without a hitch in that case.
Sounds like the server is expecting to authenticate the session but is unable to with your script. May require adding cookie support in your script; hard to say without knowing more about how the server and its login work.

If you have a port sniffer like Little Snitch you can log the transaction when you sign in and get the document from your browser, and that should provide good guidance for what's needed to emulate those browser behaviors in your script.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

cborn
Posts: 66
Joined: Fri Dec 15, 2006 11:35 pm

Re: libURLDownloadToFile follow php redirect?

Post by cborn » Wed Oct 27, 2010 9:30 pm

Richard,

Thanks for this tip, I managed to get the cookie info into a GET request and got it working! :D

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: libURLDownloadToFile follow php redirect?

Post by FourthWorld » Wed Oct 27, 2010 11:51 pm

Excellent! Glad to hear it.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply