Sarah2016

HTTP Use in AutoIt

3 posts in this topic

Hi all,

I tried a lot to solve the following problem:

In the script below, sometimes I get an error on the line lf send($data). This is because the data size may be  large with relative to the internet speed or because of interrupted internet connection. This lead to an error that will crash the running of program. Any solution to avoid this error??

 

#include-once

Global Const $HTTP_STATUS_OK = 200

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

Share this post


Link to post
Share on other sites



any help please

Share this post


Link to post
Share on other sites

Sarah2016,

You might want to set the default timeouts higher...

$oHttp.SetTimeouts('5000', '5000', '5000', '5000'); <-- milliseconds

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

Here is the main page for the http object:

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

Also, I noticed there is no size for the post in the header...

$oHttp.SetRequestHeader('Content-Length', $nValue)

 


Make yourself sheep and the wolves will eat you - Benjamin Franklin

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