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.

HTTP misunderstandings!

Help for those learning Tcl or writing their own scripts.
Post Reply
N
Neeq
Voice
Posts: 8
Joined: Thu Mar 01, 2007 10:21 am

HTTP misunderstandings!

Post by Neeq »

Hey guys,

I've been learned TCL on and off for a while and decided to have a go at tcl::http, but I have hit a brick wall and the documentation isn't the clearest thing in the world.

What I want to do is have the script access a page ( example: http://ex.com/?add ), then use POST to send data.

I have looked at the documentation for it but didn't really find any clues other than basic examples of ::http::geturl.

Any help will be appreciated.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Well, this would be accomplished in a few steps:
1st, use ::http:geturl to retrieve the page:

Code: Select all

set token [::http::geturl $url]
2nd, get the content, and parse it if necessary :

Code: Select all

set data [::http::data $token]
#parse $data and so on...
3rd, construct the query to be sent with your POST:

Code: Select all

set q [::http::formatQuery key1 value1 key2 value2]
4th, use ::http::geturl to POST the new query:

Code: Select all

set token2 [::http::geturl $url -query $q]
5th, get the content

Code: Select all

set data2 [::http::data $token2]
Since you are running this under eggdrop, it would be advisable to use the callback function of geturl, as to prevent your eggdrop from freezing.
Also, this was a very lazy example, where I simply assume the http-transaction went by flawlessly, and thus do not check for any errors or such.
NML_375
Post Reply