headers respond

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
boysky76
Posts: 48
Joined: Tue Aug 13, 2013 9:49 am

headers respond

Post by boysky76 » Tue Nov 05, 2013 10:27 am

I have to download a file from a link in this link if called httpheaders the link redirects to the server, and then starts the download, if I insert "LibUrlFollowRedirects false" then the response headers I see the link of the server, but if I leave "LibUrlFollowRedirects true "in the header can not see the file name, that I need to insert it later in the" LibUrlDownloadToFile "as the name of the file to salvare.Il first link I can not use it because it serves only as a redirect, the second link works with" LibUrlDownloadToFile "but i have not the name that appears to be in the header, if I use" get url (linkname2) "to have httpheders with the name LiveCode remains very slow because you download the entire file into memory before to give me back the headers.
How do I get the headers without downloading the file first?

I hope I have explained my problem well

boysky76
Posts: 48
Joined: Tue Aug 13, 2013 9:49 am

Re: headers respond

Post by boysky76 » Wed Nov 06, 2013 12:08 am

I found this solution, however, are not happy with this, then I download the file with (liburldownloadtofile turl,tname, "downloadDone") after I extract the name from the header Respond, and rename the file.
But I wish I could first see the name of the file and then download.

Someone suggests to me other ideas.

;)

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: headers respond

Post by Simon » Wed Nov 06, 2013 12:10 am

Hi boysky76,
How is the redirect being done? In meta tags, javascript etc.
What is the URL of the first link?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

boysky76
Posts: 48
Joined: Tue Aug 13, 2013 9:49 am

Re: headers respond

Post by boysky76 » Wed Nov 06, 2013 12:45 am

hi,

the first link is : http://w w w.sitename.com/ddl2/aHR0cDovL3d3dy5ub3d2aWRlby5jaC92aWRlby9kMWQzN2U3NTg0Nzg5fDcyNzg4fDFxd2VydHl8

Get Url (link1)

this is the http respond headers and contains the redirect url

--HTTP/1.1 302 Found
Date: Tue, 05 Nov 2013 12:21:48 GMT
Server: Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.3.17
X-Powered-By: PHP/5.3.17
Location: http://nl1a.sitename.com/name.php?type= ... I3MzQ2NDM=
Content-Length: 0
Connection: close
Content-Type: text/html--

if i set libURLFollowHttpRedirects false I can extract the location and put thsi in "tlocation" and use liburldownloadtofile (tlocation,tfilename) for download the file.
If I set libURLFollowHttpRedirects true livecode freezes or slows down because it is a large file and need "liburldownloadtofile" for download

but before to download i need extract the "Content-Disposition: " present in the http headers But I can see that only after I run the command "get" or "liburldownloadtofile" with the tlocation

HTTP/1.1 200 OK
Date: Tue, 05 Nov 2013 12:21:46 GMT
Server: Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/1.0.0-fips mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.3.21
X-Powered-By: PHP/5.3.21
Content-Disposition: attachment; filename="ff4e219a21ed3e22cf68dba97753b9cb0c.flv"
Etag: "3524601224"
Accept-Ranges: bytes
Last-Modified: Mon, 05 Aug 2013 14:26:34 GMT
Expires: Wed, 06 Nov 2013 04:21:10 GMT
Cache-Control: max-age=28800
Content-Length: 115991455
Connection: close
Content-Type: application/octet-stream

----------------

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: headers respond

Post by Simon » Wed Nov 06, 2013 1:26 am

Actually I was hoping you would post the actual URL you are using. Can't try to help without knowing what is going on.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

boysky76
Posts: 48
Joined: Tue Aug 13, 2013 9:49 am

Re: headers respond

Post by boysky76 » Wed Nov 06, 2013 8:44 am


Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: headers respond

Post by Simon » Wed Nov 06, 2013 11:57 pm

Hi boysky76,
I've got an answer for you ... might not be a good answer.

Here are the commands I used, see if you can put it together in your stack.
libURLSetLogField --Specifies a field for logging information about uploads and downloads. like the headers
resetAll --Closes all open sockets and halts all pending Internet operations. Lets you stop a download

Now with just those two can you figure out a way to make them work to grab the .flv name?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

boysky76
Posts: 48
Joined: Tue Aug 13, 2013 9:49 am

Re: headers respond

Post by boysky76 » Thu Nov 07, 2013 2:37 am

Hi simon

thanks for the answers, but even if I use "resetall" LiveCode appears to hang or rellentare very much as if the memory was not freed and called Get the url (link) to continue to load the data into memory, slowing everything

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: headers respond

Post by Simon » Thu Nov 07, 2013 3:05 am

I used put url "http://your_link" into temp
then resetAll

That was working here.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

boysky76
Posts: 48
Joined: Tue Aug 13, 2013 9:49 am

Re: headers respond

Post by boysky76 » Fri Nov 08, 2013 12:47 am

To me it keeps crashing the stack, as if the "resetall" fails to close all sockets.
the browser can read this header and take the name, I should simulate this. Basically something like this:
Liburldownloadtofile Link, tname (headers to extract libUrlLastRHHeaders), "DownloadDone"

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: headers respond

Post by Simon » Fri Nov 08, 2013 2:12 am

Try the attached stack and tell me what happens.
In the button script there is a time delay which you may have to adjust.

Simon
Attachments
sockets.zip
LC 6.1.2
(1.36 KiB) Downloaded 231 times
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Tribblehunter
Posts: 78
Joined: Wed Apr 10, 2013 9:08 pm

Re: headers respond

Post by Tribblehunter » Fri Nov 08, 2013 8:09 am

Watching with interest as I am doing something similar.
Returning to try to learn livecode again.

But much greyer at the temples than the last time.

boysky76
Posts: 48
Joined: Tue Aug 13, 2013 9:49 am

Re: headers respond

Post by boysky76 » Sat Nov 09, 2013 1:00 am

the script you sent me works, I thank you, the problem is that I now have, is that my application should extract different url one after the other and when you run the first time the command "resetall" I closed everything and I should start the script again, but by doing restart takes up the first url and not the second. (it is a bit 'complicated)

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: headers respond

Post by Simon » Sat Nov 09, 2013 1:27 am

Hello boysky76,
I'm not clear on the problem you are having. Is it just a repeat loop you are asking about?
If so just stick your url's into a variable and loop through the code.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply