This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

[SOLVED]Returning the first X characters from a remote file

Old posts that have not been replied to for several years.
Locked
User avatar
Aron
Halfop
Posts: 86
Joined: Sat Mar 15, 2003 8:35 am

[SOLVED]Returning the first X characters from a remote file

Post by Aron »

I already looked for something in the http package manual on how to do this, but i cant figure it out...

I only want to read the first 5 characters from a file or something.. Anyone have a clue on how to realize this?

Thanks in advance.
Last edited by Aron on Mon Jan 12, 2004 9:46 am, edited 1 time in total.
The best way to start learning is to start helping.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

The plain simple way:

Code: Select all

package require http

set myurl "http://www.google.com/"
set token [::http::geturl $myurl]
set content [::http::data $token]
::http::cleanup $content
# and extract stuff from $content
Ps: Place the "package require http" line outside your proc.
Once the game is over, the king and the pawn go back in the same box.
User avatar
Aron
Halfop
Posts: 86
Joined: Sat Mar 15, 2003 8:35 am

Post by Aron »

well, that is basically what i am doing already.

here's the situation:

Lately, a lot of people seem to have a lot of fun by spamming virus .jpg or images.
I created a script that will use something similiar to the code above to extract the headers, and check if they are actually a JPG file.

It works fine, but it stops working with very large JPGs... any idea what might be causing this?
The best way to start learning is to start helping.
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Hmm... not sure if it will work, but there is a way to pass additional headers to the geturl command. So you can use the http range header to get only the first few bytes if you want.

Something like this:

Code: Select all

set myurl "http://blah.com/horse.jpg"
set token [::http::geturl $myurl -headers [list "Range" "bytes=0-10"]]
set content [::http::data $token]
It should work, especially if your server supports the Range header (I think most do these days, for static files).
Locked