Jump to content

WinHTTP events


Recommended Posts

How can i get the evnts of the WinHttp com working?

And how can i check if there was a send - so we have a status code, because i want to make a udf for this but its seems like the functions dont have a return.

lobal Const Enum $WinHttpRequestOption_UserAgentString, _
  $WinHttpRequestOption_URL, _
  $WinHttpRequestOption_URLCodePage, _
  $WinHttpRequestOption_EscapePercentInURL, _
  $WinHttpRequestOption_SslErrorIgnoreFlags, _
  $WinHttpRequestOption_SelectCertificate, _
  $WinHttpRequestOption_EnableRedirects, _
  $WinHttpRequestOption_UrlEscapeDisable, _
  $WinHttpRequestOption_UrlEscapeDisableQuery, _
  $WinHttpRequestOption_SecureProtocols, _
  $WinHttpRequestOption_EnableTracing, _
  $WinHttpRequestOption_RevertImpersonationOverSsl, _
  $WinHttpRequestOption_EnableHttpsToHttpRedirects, _
  $WinHttpRequestOption_EnablePassportAuthentication, _
  $WinHttpRequestOption_MaxAutomaticRedirects, _
  $WinHttpRequestOption_MaxResponseHeaderSize, _
  $WinHttpRequestOption_MaxResponseDrainSize, _
  $WinHttpRequestOption_EnableHttp1_1, _
  $WinHttpRequestOption_EnableCertificateRevocationCheck 

$o = _WinHTTPOpen ( "get", "http://www.google.de")
;~ ConsoleWrite ($o & @error)
$o.send()
;~ ConsoleWrite ( $o.responsetext )
;~ ConsoleWrite ( $o.option ( $WinHttpRequestOption_UserAgentString ) )


Func _WinHTTPOpen ( $sMethod, $sUrl, $iAsync = 0)
    If $sMethod <> 'GET' and $sMethod <> 'POST' and $sMethod <> 'HEADER' and $sMethod <> 'PUT' Then
        Return SetError (1,0,0)
    EndIf
    $sMethod = StringUpper ($sMethod)
    if not IsString ( $sUrl ) Then Return SetError (2,0,0)
    

    $oWinHTTP = ObjCreate ('WinHttp.WinHttpRequest.5.1')
    if @error Then
        Return SetError (3,0,0)
    EndIf
;~  ObjEvent
;~  ObjEvent ( $oWinHTTP, "_Event", "IErrorInfo")
    ConsoleWrite (@error )
    
    if $oWinHTTP.Open ( $sMethod, $sUrl, $iAsync) <> '' Then
        Return SetError (4,0,0)
    EndIf
    Return $oWinHTTP
EndFunc


Func _WinHTTPStatus ( ByRef $oWinHTTP , $iMode = 1)
    if not __WinHTTPisWinHTTPObj ($oWinHTTP) Then Return SetError (1,0,0)
        
    Switch $iMode
        case 1
            Local $avStatus[2] = [ $oWinHTTP.status, $oWinHTTP.statustext]
            Return $avStatus
        case 2
            Return $oWinHTTP.status
        case 3
            Return $oWinHTTP.statustext
        case Else
            Return SetError (2,0,0)
    EndSwitch
    
EndFunc

Func _WinHTTPResponse ( ByRef $oWinHTTP, $iTimeout = -1)
    if not __WinHTTPisWinHTTPObj ($oWinHTTP) Then Return SetError (1,0,0)
    Local $vResponseText = $oWinHTTP.ResponseText
    if $vResponseText <> '' Then
        Return $vResponseText
    Else
        if  not $oWinHTTP.WaitForResponse ( $iTimeout ) Then
            Return SetError (2,0,0)
        Else
            Return $oWinHTTP.ResponseText
        EndIf
    EndIf
EndFunc

Func _WinHTTPSend (ByRef $oWinHTTP, $vData = Default)
    if not __WinHTTPisWinHTTPObj ($oWinHTTP) Then Return SetError (1,0,0)
    
    if $vData <> Default then
        $oWinHTTP.Send ($vData)
    Else
        $oWinHTTP.Send ()
    EndIf

EndFunc 

func __WinHTTPisWinHTTPObj ($oObject)
    if IsObj ($oObject) and ObjName ($oObject) == 'IWinHttpRequest' Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc

func __WinHTTPResponse ($oObject)
    If not __WinHTTPisWinHTTPObj ( $oObject ) Then Return 0
    If Execute ("$oObject.GetAllResponseHeaders()") <> '' Then
        Return 1
    Else
        Return 0
        
    EndIf
EndFunc
Edited by 4nt1h4cker
Link to comment
Share on other sites

  • 3 months later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...