Jump to content

WinHTTP Authentication


psynegy
 Share

Recommended Posts

I was working on a script to authenticate with gmail's atom feed and give the results of it's findings, but I'm having trouble working out how to authenticate with the server, I found the documentation on winhttp's authentication setup, but I'm lost with it.

MSDN Documentation:

http://msdn.microsoft.com/en-us/library/aa383144(VS.85).aspx

My code so far:

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")

MsgBox(0, "", (_HTTPRequest($oHTTP, "GET", "https://mail.google.com/mail/feed/atom") & @CRLF))

Func _HTTPRequest($oHTTP, $oMethod, $oURL, $oData = "")
    $oHTTP.Open($oMethod, $oURL, False)
    If $oMethod = "POST" Then $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
    
    
    
    $oHTTP.Send($oData)
    Return $oHTTP.ResponseText
EndFunc

Would really appreciate any help or pointers! Thanks :)

Link to comment
Share on other sites

Scratch that, I've done it!

Found a site that had used the WinHTTP object with auth in a different language and was able to work it out from that! :lmao:

Care to share? :)
Link to comment
Share on other sites

  • 1 year later...

Care to share? :(

Sorry for replying so late, but I didn't see the reply until now when I got a PM asking for the code. This is a function I pulled from one of my programs which checks a G-Mail email count. Simples.

Func CheckGmail()
    $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    
    $oHTTP.Open("GET", "https://mail.google.com/mail/feed/atom", False)
    
    $oHTTP.SetCredentials($gmail_username, $gmail_password, 0)
    
    $oHTTP.Send()
    
    $response = $oHTTP.ResponseText
    
    If StringInStr($response, "<fullcount>", false) Then
        $_COUNT = _StringBetween($response, "<fullcount>", "</fullcount>")
        $_COUNT = Int($_COUNT[0])
        $s = "s"
        If $_COUNT = 0 Then
            $_COUNT = "no"
        ElseIf $_COUNT = 1 Then
            $s = ""
        EndIf
        $_RETURN = "You have " & $_COUNT & " new email" & $s
    Else
        $_RETURN = "Gmail Error"
        $_COUNT = False
    EndIf
    
    $_INFO[$gmail_count_i] = $_RETURN
EndFunc
Link to comment
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
 Share

  • Recently Browsing   0 members

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