Sarah2016 Posted December 7, 2016 Posted December 7, 2016 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
ripdad Posted December 8, 2016 Posted December 8, 2016 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) "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now