Sign in to follow this  
Followers 0
ParoXsitiC

HTTP POST request.

8 posts in this topic

#1 ·  Posted (edited)

This isn't really a request for help, unless someone is bored. Recently i've been trying to find a way to POST data to a webpage. I first tried doing it through the IE 2.0 automation library, but the navigate method has turned wrong. It's probably my fault. Anyways, here are the 4 ways I have tried, 2 work, 2 dont.

All the scripts use the following information:

Edited by Jon

Share this post


Link to post
Share on other sites



Now for the two ways that I failed to get to work (my fault). Perhaps a non-newbie can easily fix it and help out anyone else who want to use these ways, for whatever reason.

Using IE.au3 : http://www.autoitscript.com/forum/index.php?showtopic=25629

$o_IE = _IECreate ("about:blank",0,1)
$o_IE.navigate($URL, 0, 0, $PostData ,$Header)oÝ÷ Úêå

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Here are each of the ways as attached files:

PS: TCP.au3 actually uses HTTP.au3 include files, as the creator of the HTTP UDF actually used TCP connections over the HTTPRequest objects

HTTP.au3

IE.au3

INET.au3

TCP.au3

Edited by ParoXsitiC

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Some benchmarks on the 2 working ways.

TCP uses the HTTP UDF and INET uses WININET.

A breakdown of each function and the time it takes to complete:

TCP

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

_HTTPConnect - 98.74

_HTTPPost - 0.49

_HTTPRead - 908.53

_HTTPClose - 0.24

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

TOTAL - 1008.22

INET

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

_InternetOpen - 5.48

_InternetConnect - 0.57

_HttpOpenRequest - 0.62

_HttpSendRequest - 151.7

_InternetRead - 3.15

_InternetCloseHandle - 0.33

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

TOTAL - 162.14

Averages with just a POST, no reading of response.

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

TCP 54.08

INET 125.40

Average with POST and reading response.

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

TCP 947.87

INET 131.80

It seems the _HTTPRead could use some tweaking. None the less I would recommended TCP for instance of just POSTing and INET for times when you need a more advanced option (cookies, proxies, reading..etc)

Edited by ParoXsitiC

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Now for the two ways that I failed to get to work (my fault). Perhaps a non-newbie can easily fix it and help out anyone else who want to use these ways, for whatever reason.

Using IE.au3 : http://www.autoitscript.com/forum/index.php?showtopic=25629

$o_IE = _IECreate ("about:blank",0,1)
$o_IE.navigate($URL, 0, 0, $PostData ,$Header)

http://msdn.microsoft.com/library/default....equest_send.asp

I noticed the same thing and have been struggling for hours. Read more about that here.

I wonder if (read: 'hope that') someone will write a fix / working example using IE.au3 soon.

Edited by martijn

Share this post


Link to post
Share on other sites

This one is really nice..(Alot of people will need this...)

How did you do the benchmark???

I can fix the object one.. I want to do benchmark to the other Ways so to know which way is the fastest...

Dim $obj = ObjCreate ("WinHttp.WinHttpRequest.5.1")
$obj.Open("PUT", $URL, false)
$obj.Send($PostData)
QuickOutput("Response.html",$obj.ResponseText, 2)oÝ÷ Ûú®¢×,ɦèºÛazãyËh¦Ø¨*.綶Ê&zuêì~*쵫­¢+ØìÀÌØí]¥¹!ÑÑÀ¹MÑIÅÕÍÑ!È ÅÕ½Ðí!½ÍÐÅÕ½Ðì°ÅÕ½Ðí!=MQ95¹½´ÅÕ½Ðì¤(ìÀÌØí]¥¹!ÑÑÀ¹MÑIÅÕÍÑ!È ÅÕ½ÐíUÍȵ¹ÐÅÕ½Ðì°ÅÕ½Ðí5½é¥±±¼Ô¸À¡]¥¹½ÝÌìTì]¥¹½ÝÌ9PÔ¸Ä층ULìÉØèĸ䤭¼¼ÈÀÀàÀÔÈäÀإɽà¼Ì¸ÀÅÕ½Ðì¤(ìÀÌØí]¥¹!ÑÑÀ¹MÑIÅÕÍÑ!È ÅÕ½ÐíÁÐÅÕ½Ðì°ÅÕ½ÐíÑáн¡Ñµ°±ÁÁ±¥Ñ¥½¸½á¡Ñµ°­áµ°±ÁÁ±¥Ñ¥½¸½áµ°íÄôÀ¸ä°¨¼¨íÄôÀ¸àÅÕ½Ðì¤(ìÀÌØí]¥¹!ÑÑÀ¹MÑIÅÕÍÑ!È ÅÕ½ÐíÁе1¹ÕÅÕ½Ðì°ÅÕ½Ðí¡±¸µULíÄôÀ¸Ü±¸íÄôÀ¸ÌÅÕ½Ðì¤(ìÀÌØí]¥¹!ÑÑÀ¹MÑIÅÕÍÑ!È ÅÕ½ÐíÁе¹½¥¹ÅÕ½Ðì°ÅÕ½Ðíé¥À±±ÑÅÕ½Ðì¤(ìÀÌØí]¥¹!ÑÑÀ¹MÑIÅÕÍÑ!È ÅÕ½ÐíÁе
¡ÉÍÐÅÕ½Ðì°ÅÕ½ÐíÝ¥¹½ÝÌ´ÄÈÔÔ±ÕÑ´àíÄôÀ¸Ü°¨íÄôÀ¸ÜÅÕ½Ðì¤(ìÀÌØí]¥¹!ÑÑÀ¹MÑIÅÕÍÑ!È ÅÕ½Ðí-Àµ±¥ÙÅÕ½Ðì°ÅÕ½ÐìÌÀÀÅÕ½Ðì¤(ìÀÌØí]¥¹!ÑÑÀ¹MÑIÅÕÍÑ!È ÅÕ½Ðí
½¹¹Ñ¥½¸ÅÕ½Ðì°ÅÕ½Ðí­Àµ±¥ÙÅÕ½Ðì¤(ìÀÌØí]¥¹!ÑÑÀ¹MÑIÅÕÍÑ!È ÅÕ½ÐíIÉÈÅÕ½Ðì°ÅÕ½Ðí¡ÑÑÀè¼½!=MQ95¹½´½ÕÀ¹Á¡Àýµ½õ±½¥¸µÀíÍ¥ôÅÕ½ÐìµÀìÀÌØíM¥lÁtµÀìÅÕ½ÐìÅÕ½Ðì¤(ÀÌØí]¥¹!ÑÑÀ¹MÑIÅÕÍÑ!È ÅÕ½Ðí
½½­¥ÅÕ½Ðì°ÀÌØí
½½­¥M¹¤(ÀÌØí]¥¹!ÑÑÀ¹MÑIÅÕÍÑ!È ÅÕ½Ðí
½¹Ñ¹ÐµQåÁÅÕ½Ðì°ÅÕ½ÐíÁÁ±¥Ñ¥½¸½àµÝÝܵ½É´µÕɱ¹½ÅÕ½Ðì¤(ìÀÌØí]¥¹!ÑÑÀ¹MÑIÅÕÍÑ!È ÅÕ½Ðí
½¹Ñ¹Ðµ1¹Ñ ÅÕ½Ðì°ÅÕ½ÐìääÅÕ½Ðì¤(ìÕÍɹµõ½É¹}µÀíÁÍÍݽÉôÄÔÌÈÐصÀíÉ¥ÉÐõ¥¹à¹Á¡ÀµÀíÍ¥ôÉÙÉáàØÝÍÜÕÅäÙÌäÔصÀí±½¥¸õ1½¥¸(ÀÌØí]¥¹!ÑÑÀ¹M¹ ÌäíÕÍɹµõUMI94µÀíÁÍÍݽÉõAMM]=IÌäì¤)
½¹Í½±]ɥѡ±µÀí±µÀí±µÀìÀÌØí]¥¹!ÑÑÀ¹Ñ±±IÍÁ½¹Í!ÉÌ ¤¤()
½¹Í½±]ɥѡ1µÀí1µÀí1µÀìÀÌØí]¥¹!ÑÑÀ¹IÍÁ½¹ÍQáÐ ¤¤

This is the lowest amount of headers that still give me a good login sign..

As you can see i have all the headers sent by my firefox browser..

And i canceled them one by one,,, and it still work but if i remove one of the current active headers it dont work...

Thank you about the info about wininet.dll I consider using it but its seems to much code.. i think i use winhttprequest.

Thank you

Share this post


Link to post
Share on other sites

Hey guys,

I made an example page at www.sabbgrafix.com/welcome.php which is an extremely simple post example. I use an ISSET function to display post information, if there is any submitted. The post info is "name=yourNameHere".

I used the following code, but when I try and return the body of the page after the post request is sent, I get nothing. But the @error is 0 and the other attributes state that it successfully connected and sent.

#include <IE.au3>
#include <http.au3>

$Header = "Content-Type: application/x-www-form-urlencoded"
$Host = "www.sabbgrafix.com"
$File = "/welcome.php"
$URL = "http://" & $Host & $File
$PostData = "name=steve"



$Socket = _HTTPConnect($Host)
_HTTPPost($Host, $File, $Socket, $PostData)
$recv = _HTTPRead($Socket,0)
MsgBox(0,"","BODY: "&$recv&" ERROR: "&@error)
_HTTPClose($Socket)

Any ideas as to what I'm doing wrong, or anyone know of any other more efficient ways to send POST requests to sites via AutoIt?

Thanks guys!

-Steve

Share this post


Link to post
Share on other sites

Hey guys,

I made an example page at www.sabbgrafix.com/welcome.php which is an extremely simple post example. I use an ISSET function to display post information, if there is any submitted. The post info is "name=yourNameHere".

I used the following code, but when I try and return the body of the page after the post request is sent, I get nothing. But the @error is 0 and the other attributes state that it successfully connected and sent.

 

#include <IE.au3>
#include <http.au3>

$Header = "Content-Type: application/x-www-form-urlencoded"
$Host = "www.sabbgrafix.com"
$File = "/welcome.php"
$URL = "http://" & $Host & $File
$PostData = "name=steve"



$Socket = _HTTPConnect($Host)
_HTTPPost($Host, $File, $Socket, $PostData)
$recv = _HTTPRead($Socket,0)
MsgBox(0,"","BODY: "&$recv&" ERROR: "&@error)
_HTTPClose($Socket)

Any ideas as to what I'm doing wrong, or anyone know of any other more efficient ways to send POST requests to sites via AutoIt?

Thanks guys!

-Steve

 

this is a late reply but, you forgot to issue _HTTPConnect("host.com", port)

Example:

$hsock = _HTTPConnect("www.google.com", 80)
_HTTPGet("www.google.com", "/", $sock)

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