mIRC Homepage
Posted By: WhipLash Sockets and Forms - 17/07/08 10:14 PM
Hey all,

I'v enever really bothered with sockets before, and decided i'd like to give it a bash. My first attempt involves a translator site.

The question i got is, how do i insert $1- into the form, and search for it, if the search info isnt in the url afterwards?
Posted By: starbucks_mafia Re: Sockets and Forms - 17/07/08 11:00 PM
It's probably using the HTTP POST method. You'll have to check out the <form> in the source to figure out what variables are given by the <input> tags' name attributes. Then send the variables as the message body in the manner described in the link I've given you.
Posted By: WhipLash Re: Sockets and Forms - 17/07/08 11:28 PM
Thanks, I'll tinker a bit. But im sure you'll hear from me again. lol.

I don't think i started with the easiest of scripts regarding sockets
Posted By: WhipLash Re: Sockets and Forms - 18/07/08 12:00 AM
Nope, no luck for me. *sigh*

Here's the site i'm trying to get the script working with:
Freedict

And as for the links and their values, this is what i thought it was, but its wrong:
http://www.freedict.com/onldict/onldict.php?search= $+ $1 $+ &exact=true&from=english&to=latin&fname=eng2lat1&back=lat.html

Do i have to include all that stuff from the link you gave me on POSTs using the sockwrite?
Posted By: starbucks_mafia Re: Sockets and Forms - 18/07/08 01:04 AM
Because you're using the POST method the variables shouldn't be appended to the URL, instead they should be URL encoded and sent after the headers as the message body. The length of all those variables in a string (ie. the message body length) should be sent as the Content-Length header. The Content-Type header should be application/x-www-form-urlencoded (unless the form explicitly provides a different one, which that form doesn't). The From header isn't necessary. The User-Agent header isn't technically necessary but some CGI scripts don't like it if you don't provide one. You should also specify Host and Referer headers to be safe.

Code:
alias urlencode return $replace($regsubex($1,/([^\w\d\x20])/g,% $+ $base($asc(\t),10,16)), $chr(32), +)



; Socket code starts here

var %message = search= $+ $urlencode($1) $+ &max=10&exact=true&from=English&to=Latin&fname=eng2lat1&back=lat.html

sockwrite -n moo POST /onldict/onldict.php HTTP/1.0
sockwrite -n moo Host: www.freedict.com
sockwrite -n moo User-Agent: Anything
sockwrite -n moo Referer: http://www.freedict.com/onldict/lat.html
sockwrite -n moo Content-Type: application/x-www-form-urlencoded
sockwrite -n moo Content-Length: $len(%message)
sockwrite -n moo
sockwrite -t moo %message

Posted By: WhipLash Re: Sockets and Forms - 18/07/08 09:21 AM
Thanks so much starbucks_mafia.
I got the script working and parsing the right info.

smile
Posted By: Mail Re: Sockets and Forms - 22/07/08 01:35 AM
I am doing something very similar to this, but I am picking out tokens on a web page and storing the data for future use. The problem I am having is There are tabbed spaces in the line I am reading. My question is this, $chr(60) = <, Is there a $chr number for the tab key ? If there is, It would possibly helpful to know what that number is so I can possibly $remove them from that line and get correct token.
Posted By: genius_at_work Re: Sockets and Forms - 22/07/08 03:56 AM
Tab is ascii 9

-genius_at_work
© mIRC Discussion Forums