Jump to content
Sign in to follow this  
FaridAgl

WinHttp.WinHttpRequest.5.1 Example - Any advices?

Recommended Posts

FaridAgl

AutoIt Script:

Global Const $HTTP_STATUS_OK = 200

Global $hTimer = TimerInit()
Global $sPost = HttpPost("http://www.afk-manager.ir/test/post.php", "password=WeWantThisAsMd5")
ConsoleWrite("Post: " & @TAB & @error & " " & $sPost & @TAB & TimerDiff($hTimer) & @CRLF)

Global $hTimer = TimerInit()
Global $sGet = HttpGet("http://www.afk-manager.ir/test/get.php", "password=WeWantThisAsMd5")
ConsoleWrite("Get: " & @TAB & @error & " " & $sGet & @TAB & TimerDiff($hTimer) & @CRLF)

Func HttpPost($sURL, $sData)
Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")

$oHTTP.Open("POST", $sURL, False)
If (@error) Then Return SetError(1, 0, 0)

$oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")

$oHTTP.Send($sData)
If (@error) Then Return SetError(2, 0, 0)

If ($oHTTP.Status <> $HTTP_STATUS_OK) Then Return SetError(3, 0, 0)

Return SetError(0, 0, $oHTTP.ResponseText)
EndFunc

Func HttpGet($sURL, $sData)
Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")

$oHTTP.Open("GET", $sURL & "?" & $sData, False)
If (@error) Then Return SetError(1, 0, 0)

$oHTTP.Send()
If (@error) Then Return SetError(2, 0, 0)

If ($oHTTP.Status <> $HTTP_STATUS_OK) Then Return SetError(3, 0, 0)

Return SetError(0, 0, $oHTTP.ResponseText)
EndFunc

Post.php:

<?php$password = $_POST["password"];echo md5($password);?>

Get.php:

<?php$password = $_GET["password"];echo md5($password);?>

It works well here on both Windows 7 Ultimate 32-bit and Windows XP Professional SP3 32-bit, would be nice if someone can test it on other versions of Windows as well.

And of course, I'm somehow new to this subject, let me know if there are any suggestions.

I want the GET and the POST requests to be as fast as possible (Specially GET), I did some tests and here is the result:

[HTTP UDF GET]
1 = 984.282912132673
2 = 813.896511915435
3 = 781.158836566862
4 = 791.901235916364
Total = 3371.239496531334
Average = 842.8098741328335

[HTTP UDF POST]
1 = 788.734835486743
2 = 975.688234142967
3 = 785.810779035388
4 = 847.537193542955
Total = 3397.771042208053
Average = 849.4427605520133

[WinHttp.WinHttpRequest.5.1 GET]
1 = 422.961162765649
2 = 455.738280639636
3 = 441.821516504421
4 = 390.538648365335
Total = 1711.059608275041
Average = 427.7649020687603

[WinHttp.WinHttpRequest.5.1 POST]
1 = 826.436200956633
2 = 872.366642546045
3 = 871.266802895081
4 = 875.792832686324
Total = 3445.862479084083
Average = 861.4656197710208

[InetRead]
1 = 672.120733570292
2 = 595.221462195098
3 = 561.122261209642
4 = 738.180516302658
Total = 2566.64497327769
Average = 641.6612433194225

As you can see, WinHttp.WinHttpRequest.5.1 (GET) is the fastest one.

Are you interested? Check this out:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa384106(v=vs.85).aspx

Edited by D4RKON3

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  

×