Sign in to follow this  
Followers 0
fielmann

How to simulate POST to a webserver?

7 posts in this topic

Hello autoit-friends!

I'd like to send the folowing POST command to my webserver:

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

POST /login.php?sid=d620b0ae8c1e8ac0f1155b7dddf054a1 HTTP/1.1

Host: www.mywebserver.com

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13

Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 300

Connection: keep-alive

Referer: http://www.mywebserver.com/

Cookie: Logindata=myuser%B41; PHPSESSID=d620b0ae8c1e8ac0f1155b7dddf054a1

Content-Type: application/x-www-form-urlencoded

Content-Length: 113

PHPSESSID=d620b0ae8c1e8ac0f1155b7dddf054a1&login_name=myuser&login_password=12345&Submit=enter+webserver

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

I've put the hole content of the POST into the variable $command and then I send it with TCPSend($socket, $command).

It does not work! :D

Does anybody where the problem is? :D

Share this post


Link to post
Share on other sites



I did this as a test, this is just some random site I found (http://www.snee.com/xml/crud/posttest.html). You will see that the html returned to the console is the exact same thing you will see in the browser.

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", "http://www.snee.com/xml/crud/posttest.cgi")
$oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
$oHTTP.Send("fname=john&lname=smith")
ConsoleWrite($oHTTP.ResponseText & @CRLF)

Func MyErrFunc()
   $HexNumber=hex($oMyError.number,8)
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Windescription is: " & $oMyError.windescription )

   SetError(1)
Endfunc

Share this post


Link to post
Share on other sites

I did this as a test, this is just some random site I found (http://www.snee.com/xml/crud/posttest.html). You will see that the html returned to the console is the exact same thing you will see in the browser.

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", "http://www.snee.com/xml/crud/posttest.cgi")
$oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
$oHTTP.Send("fname=john&lname=smith")
ConsoleWrite($oHTTP.ResponseText & @CRLF)

Func MyErrFunc()
   $HexNumber=hex($oMyError.number,8)
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Windescription is: " & $oMyError.windescription )

   SetError(1)
Endfunc
Looks good at the first look! :D

I've startet the script, but I can't see anything ?!? :D

Where or how can I see the result of ConsoleWrite ? :)

I've checked the autoit helpfile for consolewrite:

Local $var = "Test"

ConsoleWrite("var=" & $var & @CRLF)

; Running this in a text editor which can trap console output should produce "var=Test"

Which editor supports this feature ? :D

Share this post


Link to post
Share on other sites

Which editor supports this feature ? :D

SciTE. It's included with AutoIt.

Start -> Programs -> AutoIt v3 -> SciTE Script Editor

Share this post


Link to post
Share on other sites

If you don't want to use ConsoleWrite() in this case you can use FileWrite("new.html", $oHTTP.ResponseText) to create an actual html file of the result page.

Share this post


Link to post
Share on other sites

If you don't want to use ConsoleWrite() in this case you can use FileWrite("new.html", $oHTTP.ResponseText) to create an actual html file of the result page.

Scite is OK, but how to catch ConsoleWrite-Output with it ? :D

Share this post


Link to post
Share on other sites

Scite is OK, but how to catch ConsoleWrite-Output with it ? :D

The console is shown when you run your script. Like I said, FileWrite() and FileWriteLine() will output to a file.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0