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.

Sockets.. i guess ...

Old posts that have not been replied to for several years.
Locked
D
Drewbu

Post by Drewbu »

I wan to make a script to connect to a cgi file on my server and get the out put of the script ..... i guess i should use sokets.... and can i send data to script in post or get methods ?
If anyone can give me an example it be grate:)
thx
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

The http package can probably do what you need. I know it can do the GET method, but I don't know if it can do POST.

http://www.tcl.tk/man/tcl8.4/TclCmd/http.htm

Use http::formatQuery to generate a query string (the key1=value1&key2=value2 part).

Then use http::geturl with the -query option to contact your cgi script.

You can also do it with sockets, it's just a bit more in depth.

set sock [socket blah.com 80]
puts $sock "GET /your.cgi?key1=value1&key2=value2 HTTP/1.0"
puts $sock "Host: blah.com"
puts $sock "Connection: close"
puts $sock ""
flush $sock
then read the data back from the sock with gets or read.
D
Drewbu

Post by Drewbu »

Thanks
I'm gona try http package first...
Is it already build in to tcl or i have to install it somehow?
:smile:
D
Drewbu

Post by Drewbu »

WELL i'm trying sockets...
scripts is

Code: Select all

proc test {nick uhand handle chan input} {
putserv "PRIVMSG $nick :oK it's coming"
set sock [socket http://www.eggdrop.hut.ru 80] 
puts $sock "GET cgi-bin/test.cgi HTTP/1.0" 
puts $sock "Host: eggdrop.hut.ru" 
puts $sock "Connection: close" 
puts $sock "" 
flush $sock
putserv "PRIVMSG $nick :[read $sock 700]"
}
and it send me this
[17:51] <Winnis> OK it's coming
[17:51] <Winnis> HTTP/1.0 400 Bad Request
but the page is where .. what do i do wrong?

<font size=-1>[ This Message was edited by: Drewbu on 2002-05-01 18:54 ]</font>
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Well you forgot the / in front of cgi-bin
D
Drewbu

Post by Drewbu »

Ok thanks, but i get this msg now HTTP/1.1 200 OK
I know it means that it connected, but how do i get the source of the page?
D
Dakota

Post by Dakota »

This is the first line of the server's header reply. You should use 'read' without the third parameter.
D
Drewbu

Post by Drewbu »

it don't work ... still gives me that 200 http ok thing
..:smile:
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

It is working lol

Your putserv line only sends the first line of the response. You can't send newlines within a private message.

putserv "PRIVMSG $nick :[read $sock 700]"

You have to read the whole response into a variable, then use 'split' to split it up (using 'n'), and then send one line at a time with PRIVMSG.
D
Drewbu

Post by Drewbu »

thx ....
lol .... i'm stupid .... :smile:
Locked