Jump to content

Logging in via https?


Recommended Posts

So I've just started using AutoIt, and it's kind of confusing..

Basically, I want to make a script that logs into a website, but the website sends the login info via https. That being said, I'm assuming regular winhttp isn't going to do the trick.

Now, should I try WinINet as an alternative? The WinINet thread (here) mentioned https in the title, but I wasn't sure how to go about using it..

I know this might sound like something big to start off on, but I enjoy a challenge. :D

Also, I hope it's not something obvious. It's now 6am so I might have missed something obvious. :/

Edited by Bkid
Link to comment
Share on other sites

WinHTTP does support HTTPS, but it is not trivial: MSDN

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

From what I've heard, IE Functions are slow. Isn't there any alternative in autoit?

Balderdash! Hearsay! Unfounded drivel!

That said :D , browser creation can be considered slow but once that is accomplished things work quite fast. If you don't need client-side processing, a content layout engine, authentication, CSS etc. that are features of a browser then by all means use low level functions like INetGet or direct TCP/IP calls for data. There are many benifits to having access to the browser and browser DOM for other functions.

The IE functions work the same for https as they do for http. There are literally thousands of examples in the forum as well as the helpfile. Try Search.

Dale

Edit: typo

Edited by DaleHohm

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

#include <HTTP.au3>

Dim $Sock
Dim $sHost, $sPage, $sData, $sSrc
Dim $sUsername, $sPassword

$sUsername = 'MyUserName'
$sPassword = 'MyPassWord'

$sHost = 'www.autoitscript.com'
$sPage = '/forum/index.php?act=Login&CODE=01'
$sData = 'referer=http%3A%2F%2Fwww.autoitscript.com%2Fforum%2Findex.php%3Fact%3DLogin%26CODE%3D00&UserName=' & _
        _EncodeURL($sUsername) & '&PassWord=' & _EncodeURL($sPassword) & '&CookieDate=1'

$Sock = _HTTPConnect($sHost)
_HTTPPost($sHost, $sPage, $Sock, $sData)
$sSrc = _HTTPRead($Sock)

If StringInStr($sSrc, 'attention') Then
    MsgBox(0x10, 'Attention!', 'The user or password or both are not correct')
Else
    Local $aWelcome = StringRegExp($sSrc, '(?i)<p>You are now logged in as: (.*?)<br\s*/>', 1)
    If IsArray($aWelcome) Then
        MsgBox(0x40, 'Welcome', 'You are now logged in as: ' & $aWelcome[0] & @CRLF & 'Please wait while we transfer you...')
    Else
        MsgBox(0x40, 'Welcome', ':)')
    EndIf
EndIf

_HTTPClose($Sock)
Exit

Func _EncodeURL($sString)
    Local $sStr = ''
    Local $sChr
    
    For $i = 1 To StringLen($sString)
        $sChr = StringMid($sString, $i, 1)
        If StringRegExp($sChr, '[\w*@-]') Then
            $sStr &= $sChr
        Else
            $sStr &= StringFormat('%%%02X', Asc($sChr))
        EndIf
    Next
    Return $sStr
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...