Jump to content

WinHttp Form Fill


 Share

Recommended Posts

Since I know that the examples thread isn't a place for help and support and the answers I got there didn't quite help me figure out what I'm doing wrong, I'll post here. (Thanks, trancexx, for clearing some things up though.)

I've got a form that I'm trying to fill on a secure site, but it's located in a Javascript redirect, so I don't know how to get WinHttp to find the form. The code below just gives me @error 1.

#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include <WinHttp.au3>

Opt("TrayIconDebug", 1)
Opt("MustDeclareVars", 1)

Global $aError[7] = ["", "No forms on the page", "Invalid form", "No forms with specified attributes on the page", "Connection problems", "Action is invalid", "Invalid session handle passed"]
Global $hOpen = _WinHttpOpen()
Global $hConnect = _WinHttpConnect($hOpen, "www.bcwebtrack.com", $INTERNET_DEFAULT_HTTPS_PORT)
Global $sUser = "MyUser"
Global $sPass = "MyPass"
Global $sRead = _WinHttpSimpleFormFill($hConnect, "/webtrack/index.php", "name:LoginForm", "UserId", $sUser, "Password", $sPass, "CompanyId", $sUser)
If @error Then MsgBox(0, "Form Fill Error", $aError[@error])
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

If $sRead Then ConsoleWrite($sRead & @CRLF)

 

The following code will give me the source with the forms:

Global $hRequest = _WinHttpOpenRequest($hConnect, "POST", "/webtrack/index.php", Default, Default, Default, $WINHTTP_FLAG_SECURE)
_WinHttpSendRequest($hRequest)
_WinHttpReceiveResponse($hRequest)
If _WinHttpQueryDataAvailable($hRequest) Then
    Global $sHTML
    Do
        $sHTML &= _WinHttpReadData($hRequest) ;Read HTTP data (source code)
    Until @error
EndIf

 

Any and all help would be very much appreciated, please and thank you.

Link to comment
Share on other sites

In the meantime, I got the following to work:

; #FUNCTION# ;===============================================================================
; Name...........: _WinHttpSimpleFormFillSSL
; Description ...: Fills web form.
; Syntax.........: _WinHttpSimpleFormFillSSL(ByRef $hInternet [, $sActionPage = Default [, $sFormId = Default [, $sFieldId1 = Default [, $sData1 = Default [, (...)]]]]])
; Parameters ....: $hInternet - Handle returned by _WinHttpConnect() or string variable with form.
;                  $sActionPage -  [optional] path to the page with form or session handle if $hInternet is string (default: "" - empty string; meaning 'default' page on the server in former).
;                  $sFormId - [optional] Id of the form. Can be name or zero-based index too (read Remarks section).
;                  $sFieldId1 - [optional] Id of the input.
;                  $sData1 - [optional] Data to set to coresponding field.
;                  (...) - [optional] Other pairs of Id/Data. Overall number of fields is 40.
; Return values .: Success - Returns HTML source of the page returned by the server on submitted form.
;                  Failure - Returns empty string and sets @error:
;                  |1 - No forms on the page
;                  |2 - Invalid form
;                  |3 - No forms with specified attributes on the page
;                  |4 - Connection problems
;                  |5 - form's "action" is invalid
;                  |6 - invalid session handle passed
; Author ........: trancexx, GMK
; Remarks .......: In case form requires redirection and [[$hInternet]] is internet handle, this handle will be closed and replaced with new and required one.
;                  +When [[$hInternet]] is form string, form's "action" must specify URL and [[$sActionPage]] parameter must be session handle. On succesful call this variable will be changed to connection handle of the internally made connection.
;                  Don't forget to close this handle after the function returns and when no longer needed.
;                  +[[$sFormId]] specifies Id of the form same as [[.getElementById(FormId)]]. Aditionally you can use [["index:FormIndex"]] to
;                  identify form by its zero-based index number (in case of e.g. three forms on some page first one will have index=0, second index=1, third index=2).
;                  Use [["name:FormName"]] to identify form by its name like with [[.getElementsByName(FormName)]]. FormName will be taken to be what's right of colon mark.
;                  In that case first form with that name is filled.
;                  +As for fields, If [["name:FieldName"]] option is used all the fields except last with that name are removed from the form. Last one is filled with specified $sData data.
;                  +This function can be used to fill forms with up to 40 fields at once.
;                  +"Submit" control you want to keep (click) set to True. If no such control is set then the first one found in the form is "clicked"
;                  and the other removed from the submitted form. "Checkbox" and "Button" input types are removed from the submitted form unless explicitly set. Same goes for "Radio" with exception that
;                  only one such control can be set, the rest are removed. These controls are set by their values. Wrong value makes them invalid and therefore not part of the submitted data.
;                  +All other non-set fields are left default.
;                  +Last (superfluous) argument will be treated as HTTP request header data to add.
;                  +
;                  +If this function is used to upload multiple files then there are two available ways. Default would be to submit the form following RFC2388 specification.
;                  In that case every file is represented as multipart/mixed part embedded within the multipart/form-data.
;                  +If you want to upload using alternative way (to avoid certain PHP bug that could exist on server side) then prefix the file string with [["PHP#50338:"]] string.
;                  +For example: [[..."name:files[]", "PHP#50338:" & $sFile1 & "|" & $sFile2 ...]]
;                  +Muliple files are always separated with vertical line ASCII character when filling the form.
; Related .......: _WinHttpConnect
;============================================================================================
Func _WinHttpSimpleFormFillSSL(ByRef $hInternet, $sActionPage = Default, $sFormId = Default, $sFieldId1 = Default, $sData1 = Default, $sFieldId2 = Default, $sData2 = Default, $sFieldId3 = Default, $sData3 = Default, $sFieldId4 = Default, $sData4 = Default, $sFieldId5 = Default, $sData5 = Default, $sFieldId6 = Default, $sData6 = Default, $sFieldId7 = Default, $sData7 = Default, $sFieldId8 = Default, $sData8 = Default, $sFieldId9 = Default, $sData9 = Default, $sFieldId10 = Default, $sData10 = Default, _
        $sFieldId11 = Default, $sData11 = Default, $sFieldId12 = Default, $sData12 = Default, $sFieldId13 = Default, $sData13 = Default, $sFieldId14 = Default, $sData14 = Default, $sFieldId15 = Default, $sData15 = Default, $sFieldId16 = Default, $sData16 = Default, $sFieldId17 = Default, $sData17 = Default, $sFieldId18 = Default, $sData18 = Default, $sFieldId19 = Default, $sData19 = Default, $sFieldId20 = Default, $sData20 = Default, _
        $sFieldId21 = Default, $sData21 = Default, $sFieldId22 = Default, $sData22 = Default, $sFieldId23 = Default, $sData23 = Default, $sFieldId24 = Default, $sData24 = Default, $sFieldId25 = Default, $sData25 = Default, $sFieldId26 = Default, $sData26 = Default, $sFieldId27 = Default, $sData27 = Default, $sFieldId28 = Default, $sData28 = Default, $sFieldId29 = Default, $sData29 = Default, $sFieldId30 = Default, $sData30 = Default, _
        $sFieldId31 = Default, $sData31 = Default, $sFieldId32 = Default, $sData32 = Default, $sFieldId33 = Default, $sData33 = Default, $sFieldId34 = Default, $sData34 = Default, $sFieldId35 = Default, $sData35 = Default, $sFieldId36 = Default, $sData36 = Default, $sFieldId37 = Default, $sData37 = Default, $sFieldId38 = Default, $sData38 = Default, $sFieldId39 = Default, $sData39 = Default, $sFieldId40 = Default, $sData40 = Default)
    #forceref $sFieldId1, $sData1, $sFieldId2, $sData2, $sFieldId3, $sData3, $sFieldId4, $sData4, $sFieldId5, $sData5, $sFieldId6, $sData6, $sFieldId7, $sData7, $sFieldId8, $sData8, $sFieldId9, $sData9, $sFieldId10, $sData10
    #forceref $sFieldId11, $sData11, $sFieldId12, $sData12, $sFieldId13, $sData13, $sFieldId14, $sData14, $sFieldId15, $sData15, $sFieldId16, $sData16, $sFieldId17, $sData17, $sFieldId18, $sData18, $sFieldId19, $sData19, $sFieldId20, $sData20
    #forceref $sFieldId21, $sData21, $sFieldId22, $sData22, $sFieldId23, $sData23, $sFieldId24, $sData24, $sFieldId25, $sData25, $sFieldId26, $sData26, $sFieldId27, $sData27, $sFieldId28, $sData28, $sFieldId29, $sData29, $sFieldId30, $sData30
    #forceref $sFieldId31, $sData31, $sFieldId32, $sData32, $sFieldId33, $sData33, $sFieldId34, $sData34, $sFieldId35, $sData35, $sFieldId36, $sData36, $sFieldId37, $sData37, $sFieldId38, $sData38, $sFieldId39, $sData39, $sFieldId40, $sData40
    __WinHttpDefault($sActionPage, "")
    ; Get page source
    Local $hOpen, $sHTML, $fVarForm, $hRequest
    If IsString($hInternet) Then ; $hInternet is page source
        $sHTML = $hInternet
        If _WinHttpQueryOption($sActionPage, $WINHTTP_OPTION_HANDLE_TYPE) <> $WINHTTP_HANDLE_TYPE_SESSION Then Return SetError(6, 0, "")
        $hOpen = $sActionPage
        $fVarForm = True
    Else
        $hRequest = _WinHttpOpenRequest($hInternet, Default, $sActionPage, Default, Default, Default, $WINHTTP_FLAG_SECURE)
        _WinHttpAddRequestHeaders($hRequest, "Accept: text/html;q=0.9,text/plain;q=0.8,*/*;q=0.5")
        _WinHttpSendRequest($hRequest)
        _WinHttpReceiveResponse($hRequest)
        If _WinHttpQueryDataAvailable($hRequest) Then
            Do
                $sHTML &= _WinHttpReadData($hRequest)
            Until @error
        EndIf
        _WinHttpCloseHandle($hRequest)
    EndIf
    $sHTML = StringRegExpReplace($sHTML, "(?s)<!--.*?-->", "") ; removing comments
    $sHTML = StringRegExpReplace($sHTML, "(?s)<!\[CDATA\[.*?\]\]>", "") ; removing CDATA
    Local $fSend = False ; preset 'Sending flag'
    ; Find all forms on page
    Local $aForm = StringRegExp($sHTML, "(?si)<\s*form\s*(.*?)<\s*/form\s*>", 3)
    If @error Then Return SetError(1, 0, "") ; There are no forms available
    ; Process input
    Local $fGetFormByName, $sFormName, $fGetFormByIndex, $fGetFormById, $iFormIndex
    Local $aSplitForm = StringSplit($sFormId, ":", 2)
    If @error Then ; like .getElementById(FormId)
        $fGetFormById = True
    Else
        If $aSplitForm[0] = "name" Then ; like .getElementsByName(FormName)
            $sFormName = $aSplitForm[1]
            $fGetFormByName = True
        ElseIf $aSplitForm[0] = "index" Then
            $iFormIndex = Number($aSplitForm[1])
            $fGetFormByIndex = True
        Else ; like .getElementById(FormId)
            $sFormId = $aSplitForm[0]
            $fGetFormById = True
        EndIf
    EndIf
    ; Variables
    Local $sForm, $sAttributes, $aAttributes, $aInput, $sAdditionalHeaders
    Local $iNumArgs = @NumParams
    If Not Mod($iNumArgs, 2) Then $sAdditionalHeaders = Eval("sFieldId" & $iNumArgs / 2 - 1)
    Local $iNumParams = Ceiling(($iNumArgs - 2) / 2) - 1
    Local $sAddData
    Local $aCrackURL, $sNewURL, $iScheme = $INTERNET_SCHEME_HTTPS
    ; Loop thru all forms on the page and find one that was specified
    For $iFormOrdinal = 0 To UBound($aForm) - 1
        If $fGetFormByIndex And $iFormOrdinal <> $iFormIndex Then ContinueLoop
        $sForm = $aForm[$iFormOrdinal]
        ; Extract form attributes
        $sAttributes = StringRegExp($sForm, "(?s)(.*?)>", 3)
        If Not @error Then $sAttributes = $sAttributes[0]
        $aAttributes = StringRegExp($sAttributes, '\s*([^=]+)\h*=\h*(?:"|''|)(.*?)(?:"|''| |\Z)', 3) ; e.g. method="post" or method=post or method='post'
        If @error Then Return SetError(2, 0, "") ; invalid form
        If Mod(UBound($aAttributes), 2) Then ReDim $aAttributes[UBound($aAttributes) + 1]
        Local $sAction = "", $sAccept = "", $sEnctype = "", $sMethod = "", $sName = "", $sId = ""
        ; Check set attributes
        For $i = 0 To UBound($aAttributes) - 2 Step 2 ; array of form attributes
            Switch $aAttributes[$i]
                Case "action"
                    $sAction = StringReplace($aAttributes[$i + 1], "&amp;", "&")
                Case "accept"
                    $sAccept = $aAttributes[$i + 1]
                Case "enctype"
                    $sEnctype = $aAttributes[$i + 1]
                Case "id"
                    $sId = $aAttributes[$i + 1]
                    If $fGetFormById And $sFormId <> Default And $aAttributes[$i + 1] <> $sFormId Then ContinueLoop 2
                Case "method"
                    $sMethod = $aAttributes[$i + 1]
                Case "name"
                    $sName = $aAttributes[$i + 1]
                    If $fGetFormByName And $sFormName <> $sName Then ContinueLoop 2
            EndSwitch
        Next
        If $sFormId <> Default And $fGetFormById And $sFormId <> $sId Then ContinueLoop
        If $fGetFormByName And $sFormName <> $sName Then ContinueLoop
        If Not $sMethod Then $sMethod = "GET"
        If $sMethod = "GET" Then $sEnctype = ""
        $aCrackURL = _WinHttpCrackUrl($sAction)
        If @error Then
            If $sAction Then
                If StringLeft($sAction, 1) <> "/" Then
                    Local $sCurrent
                    Local $aURL = StringRegExp($sActionPage, '(.*)/', 3)
                    If Not @error Then $sCurrent = $aURL[0]
                    If $sCurrent Then $sAction = $sCurrent & "/" & $sAction
                EndIf
                If StringLeft($sAction, 1) = "?" Then $sAction = $sActionPage & $sAction
            EndIf
            If Not $sAction Then $sAction = $sActionPage
            $sAction = StringRegExpReplace($sAction, "\A(/*\.\./)*", "") ; /../
        Else
            $iScheme = $aCrackURL[1]
            $sNewURL = $aCrackURL[2]
            $sAction = $aCrackURL[6] & $aCrackURL[7]
        EndIf
        If $fVarForm And Not $sNewURL Then Return SetError(5, 0, "") ; "action" must have URL specified
        ; Requested form is found. Set $fSend flag to true
        $fSend = True
        Local $aSplit, $sBoundary, $sPassedId, $sPassedData, $iNumRepl, $fMultiPart = False, $sSubmit, $sRadio, $sCheckBox, $sButton
        Local $sGrSep = Chr(29)
        $aInput = StringRegExp($sForm, "(?si)<\h*(?:input|textarea|label|fieldset|legend|select|optgroup|option|button)\h*(.*?)/*\h*>", 3)
        If @error Then Return SetError(2, 0, "") ; invalid form
        Local $aInputIds[4][UBound($aInput)]
        Switch $sEnctype
            Case "", "application/x-www-form-urlencoded"
                For $i = 0 To UBound($aInput) - 1 ; for all input elements
                    __WinHttpFormAttrib($aInputIds, $i, $aInput[$i])
                    If $aInputIds[1][$i] Then ; if there is 'name' field then add it
                        $aInputIds[2][$i] = __WinHttpURLEncode($aInputIds[2][$i])
                        $sAddData &= $aInputIds[1][$i] & "=" & $aInputIds[2][$i] & "&"
                        If $aInputIds[3][$i] = "submit" Then $sSubmit &= $aInputIds[1][$i] & "=" & $aInputIds[2][$i] & $sGrSep ; add to overall "submit" string
                        If $aInputIds[3][$i] = "radio" Then $sRadio &= $aInputIds[1][$i] & "=" & $aInputIds[2][$i] & $sGrSep ; add to overall "radio" string
                        If $aInputIds[3][$i] = "checkbox" Then $sCheckBox &= $aInputIds[1][$i] & "=" & $aInputIds[2][$i] & $sGrSep ; add to overall "checkbox" string
                        If $aInputIds[3][$i] = "button" Then $sButton &= $aInputIds[1][$i] & "=" & $aInputIds[2][$i] & $sGrSep ; add to overall "button" string
                    EndIf
                Next
                $sSubmit = StringTrimRight($sSubmit, 1)
                $sRadio = StringTrimRight($sRadio, 1)
                $sCheckBox = StringTrimRight($sCheckBox, 1)
                $sButton = StringTrimRight($sButton, 1)
                $sAddData = StringTrimRight($sAddData, 1)
                For $k = 1 To $iNumParams
                    $sPassedData = __WinHttpURLEncode(Eval("sData" & $k))
                    $sPassedId = Eval("sFieldId" & $k)
                    $aSplit = StringSplit($sPassedId, ":", 2)
                    If @error Or $aSplit[0] <> "name" Then ; like .getElementById
                        For $j = 0 To UBound($aInputIds, 2) - 1
                            If $aInputIds[0][$j] = $sPassedId Then
                                If $aInputIds[3][$j] = "submit" Then
                                    If $sPassedData = True Then ; if this "submit" is set to TRUE then
                                        If $sSubmit Then ; If not already processed; only the first is valid
                                            Local $fDelId = False
                                            For $sChunkSub In StringSplit($sSubmit, $sGrSep, 3) ; go tru all "submit" controls
                                                If $sChunkSub = $aInputIds[1][$j] & "=" & $aInputIds[2][$j] Then
                                                    If $fDelId Then $sAddData = StringRegExpReplace($sAddData, "(?i)(?:&|\A)\Q" & $sChunkSub & "\E(?:&|\Z)", "&", 1)
                                                    $fDelId = True
                                                Else
                                                    $sAddData = StringRegExpReplace($sAddData, "(?i)(?:&|\A)\Q" & $sChunkSub & "\E(?:&|\Z)", "&") ; delete all but the TRUE one
                                                EndIf
                                                __WinHttpTrimBounds($sAddData, "&")
                                            Next
                                            $sSubmit = ""
                                        EndIf
                                    EndIf
                                ElseIf $aInputIds[3][$j] = "radio" Then
                                    If $sPassedData = $aInputIds[2][$j] Then
                                        For $sChunkSub In StringSplit($sRadio, $sGrSep, 3) ; go tru all "radio" controls
                                            If $sChunkSub = $aInputIds[1][$j] & "=" & $sPassedData Then
                                                $sAddData = StringRegExpReplace(StringReplace($sAddData, "&", "&&"), "(?i)(?:&|\A)\Q" & $aInputIds[1][$j] & "\E(.*?)(?:&|\Z)", "&")
                                                $sAddData = StringReplace(StringReplace($sAddData, "&&", "&"), "&&", "&")
                                                If StringLeft($sAddData, 1) = "&" Then $sAddData = StringTrimLeft($sAddData, 1)
                                                $sAddData &= "&" & $sChunkSub
                                                $sRadio = StringRegExpReplace(StringReplace($sRadio, $sGrSep, $sGrSep & $sGrSep), "(?i)(?:" & $sGrSep & "|\A)\Q" & $aInputIds[1][$j] & "\E(.*?)(?:" & $sGrSep & "|\Z)", $sGrSep)
                                                $sRadio = StringReplace(StringReplace($sRadio, $sGrSep & $sGrSep, $sGrSep), $sGrSep & $sGrSep, $sGrSep)
                                            EndIf
                                        Next
                                    EndIf
                                ElseIf $aInputIds[3][$j] = "checkbox" Then
                                    $sCheckBox = StringRegExpReplace($sCheckBox, "(?i)\Q" & $aInputIds[1][$j] & "=" & $sPassedData & "\E" & $sGrSep & "*", "")
                                    __WinHttpTrimBounds($sCheckBox, $sGrSep)
                                ElseIf $aInputIds[3][$j] = "button" Then
                                    $sButton = StringRegExpReplace($sButton, "(?i)\Q" & $aInputIds[1][$j] & "=" & $sPassedData & "\E" & $sGrSep & "*", "")
                                    __WinHttpTrimBounds($sButton, $sGrSep)
                                Else
                                    $sAddData = StringRegExpReplace(StringReplace($sAddData, "&", "&&"), "(?i)(?:&|\A)\Q" & $aInputIds[1][$j] & "=" & $aInputIds[2][$j] & "\E(?:&|\Z)", "&" & $aInputIds[1][$j] & "=" & $sPassedData & "&")
                                    $iNumRepl = @extended
                                    $sAddData = StringReplace($sAddData, "&&", "&")
                                    If $iNumRepl > 1 Then ; equalize ; TODO: remove duplicates
                                        $sAddData = StringRegExpReplace($sAddData, "(?i)(?:&|\A)\Q" & $aInputIds[1][$j] & "\E=.*?(?:&|\Z)", "&", $iNumRepl - 1)
                                    EndIf
                                    __WinHttpTrimBounds($sAddData, "&")
                                EndIf
                            EndIf
                        Next
                    Else ; like .getElementsByName
                        For $j = 0 To UBound($aInputIds, 2) - 1
                            If $aInputIds[3][$j] = "submit" Then
                                If $sPassedData = True Then ; if this "submit" is set to TRUE then
                                    If $aInputIds[1][$j] = $aSplit[1] Then
                                        If $sSubmit Then ; If not already processed; only the first is valid
                                            Local $fDel = False
                                            For $sChunkSub In StringSplit($sSubmit, $sGrSep, 3) ; go tru all "submit" controls
                                                If $sChunkSub = $aInputIds[1][$j] & "=" & $aInputIds[2][$j] Then
                                                    If $fDel Then $sAddData = StringRegExpReplace($sAddData, "(?i)(?:&|\A)\Q" & $sChunkSub & "\E(?:&|\Z)", "&", 1)
                                                    $fDel = True
                                                Else
                                                    $sAddData = StringRegExpReplace($sAddData, "(?i)(?:&|\A)\Q" & $sChunkSub & "\E(?:&|\Z)", "&") ; delete all but the TRUE one
                                                EndIf
                                                __WinHttpTrimBounds($sAddData, "&")
                                            Next
                                            $sSubmit = ""
                                        EndIf
                                        ContinueLoop 2 ; process next parameter
                                    EndIf
                                Else ; False means do nothing
                                    ContinueLoop 2 ; process next parameter
                                EndIf
                            ElseIf $aInputIds[1][$j] = $aSplit[1] And $aInputIds[3][$j] = "radio" Then
                                For $sChunkSub In StringSplit($sRadio, $sGrSep, 3) ; go tru all "radio" controls
                                    If $sChunkSub = $aInputIds[1][$j] & "=" & $sPassedData Then
                                        $sAddData = StringReplace(StringReplace(StringRegExpReplace(StringReplace($sAddData, "&", "&&"), "(?i)(?:&|\A)\Q" & $aInputIds[1][$j] & "\E(.*?)(?:&|\Z)", "&"), "&&", "&"), "&&", "&")
                                        If StringLeft($sAddData, 1) = "&" Then $sAddData = StringTrimLeft($sAddData, 1)
                                        $sAddData &= "&" & $sChunkSub
                                        $sRadio = StringRegExpReplace(StringReplace($sRadio, $sGrSep, $sGrSep & $sGrSep), "(?i)(?:" & $sGrSep & "|\A)\Q" & $aInputIds[1][$j] & "\E(.*?)(?:" & $sGrSep & "|\Z)", $sGrSep)
                                        $sRadio = StringReplace(StringReplace($sRadio, $sGrSep & $sGrSep, $sGrSep), $sGrSep & $sGrSep, $sGrSep)
                                    EndIf
                                Next
                                ContinueLoop 2 ; process next parameter
                            ElseIf $aInputIds[1][$j] = $aSplit[1] And $aInputIds[3][$j] = "checkbox" Then
                                $sCheckBox = StringRegExpReplace($sCheckBox, "(?i)\Q" & $aInputIds[1][$j] & "=" & $sPassedData & "\E" & $sGrSep & "*", "")
                                __WinHttpTrimBounds($sCheckBox, $sGrSep)
                                ContinueLoop 2 ; process next parameter
                            ElseIf $aInputIds[1][$j] = $aSplit[1] And $aInputIds[3][$j] = "button" Then
                                $sButton = StringRegExpReplace($sButton, "(?i)\Q" & $aInputIds[1][$j] & "=" & $sPassedData & "\E" & $sGrSep & "*", "")
                                __WinHttpTrimBounds($sButton, $sGrSep)
                                ContinueLoop 2 ; process next parameter
                            EndIf
                        Next
                        $sAddData = StringRegExpReplace(StringReplace($sAddData, "&", "&&"), "(?i)(?:&|\A)\Q" & $aSplit[1] & "\E=.*?(?:&|\Z)", "&" & $aSplit[1] & "=" & $sPassedData & "&")
                        $iNumRepl = @extended
                        $sAddData = StringReplace($sAddData, "&&", "&")
                        If $iNumRepl > 1 Then ; remove duplicates
                            $sAddData = StringRegExpReplace($sAddData, "(?i)(?:&|\A)\Q" & $aSplit[1] & "\E=.*?(?:&|\Z)", "&", $iNumRepl - 1)
                        EndIf
                        __WinHttpTrimBounds($sAddData, "&")
                    EndIf
                Next
                __WinHttpFinalizeCtrls($sSubmit, $sRadio, $sCheckBox, $sButton, $sAddData, $sGrSep, "&")
                If $sMethod = "GET" Then
                    $sAction &= "?" & $sAddData
                    $sAddData = "" ; not to send as addition to the request (this is GET)
                EndIf
            Case "multipart/form-data"
                If $sMethod = "POST" Then ; can't be GET
                    $fMultiPart = True
                    ; Define boundary line
                    $sBoundary = StringFormat("%s%.5f", "----WinHttpBoundaryLine_", Random(10000, 99999))
                    Local $sCDisp = 'Content-Disposition: form-data; name="'
                    For $i = 0 To UBound($aInput) - 1 ; for all input elements
                        __WinHttpFormAttrib($aInputIds, $i, $aInput[$i])
                        If $aInputIds[1][$i] Then ; if there is 'name' field
                            If $aInputIds[3][$i] = "file" Then
                                $sAddData &= "--" & $sBoundary & @CRLF & _
                                        $sCDisp & $aInputIds[1][$i] & '"; filename=""' & @CRLF & @CRLF & _
                                        $aInputIds[2][$i] & @CRLF
                            Else
                                $sAddData &= "--" & $sBoundary & @CRLF & _
                                        $sCDisp & $aInputIds[1][$i] & '"' & @CRLF & @CRLF & _
                                        $aInputIds[2][$i] & @CRLF
                            EndIf
                            If $aInputIds[3][$i] = "submit" Then $sSubmit &= "--" & $sBoundary & @CRLF & _
                                    $sCDisp & $aInputIds[1][$i] & '"' & @CRLF & @CRLF & _
                                    $aInputIds[2][$i] & @CRLF & $sGrSep
                            If $aInputIds[3][$i] = "radio" Then $sRadio &= "--" & $sBoundary & @CRLF & _
                                    $sCDisp & $aInputIds[1][$i] & '"' & @CRLF & @CRLF & _
                                    $aInputIds[2][$i] & @CRLF & $sGrSep
                            If $aInputIds[3][$i] = "checkbox" Then $sCheckBox &= "--" & $sBoundary & @CRLF & _
                                    $sCDisp & $aInputIds[1][$i] & '"' & @CRLF & @CRLF & _
                                    $aInputIds[2][$i] & @CRLF & $sGrSep
                            If $aInputIds[3][$i] = "button" Then $sButton &= "--" & $sBoundary & @CRLF & _
                                    $sCDisp & $aInputIds[1][$i] & '"' & @CRLF & @CRLF & _
                                    $aInputIds[2][$i] & @CRLF & $sGrSep
                        EndIf
                    Next
                    $sSubmit = StringTrimRight($sSubmit, 1)
                    $sRadio = StringTrimRight($sRadio, 1)
                    $sCheckBox = StringTrimRight($sCheckBox, 1)
                    $sButton = StringTrimRight($sButton, 1)
                    $sAddData &= "--" & $sBoundary & "--" & @CRLF
                    For $k = 1 To $iNumParams
                        $sPassedData = Eval("sData" & $k)
                        $sPassedId = Eval("sFieldId" & $k)
                        $aSplit = StringSplit($sPassedId, ":", 2)
                        If @error Or $aSplit[0] <> "name" Then ; like getElementById
                            For $j = 0 To UBound($aInputIds, 2) - 1
                                If $aInputIds[0][$j] = $sPassedId Then
                                    If $aInputIds[3][$j] = "file" Then
                                        $sAddData = StringReplace($sAddData, _
                                                $sCDisp & $aInputIds[1][$j] & '"; filename=""' & @CRLF & @CRLF & $aInputIds[2][$j] & @CRLF, _
                                                __WinHttpFileContent($sAccept, $aInputIds[1][$j], $sPassedData, $sBoundary))
                                    ElseIf $aInputIds[3][$j] = "submit" Then
                                        If $sPassedData = True Then ; if this "submit" is set to TRUE then
                                            If $sSubmit Then ; If not already processed; only the first is valid
                                                Local $fMDelId = False
                                                For $sChunkSub In StringSplit($sSubmit, $sGrSep, 3) ; go tru all "submit" controls
                                                    If $sChunkSub = "--" & $sBoundary & @CRLF & _
                                                            $sCDisp & $aInputIds[1][$j] & '"' & @CRLF & @CRLF & _
                                                            $aInputIds[2][$j] & @CRLF Then
                                                        If $fMDelId Then $sAddData = StringReplace($sAddData, $sChunkSub, "", 1) ; Removing duplicates
                                                        $fMDelId = True
                                                    Else
                                                        $sAddData = StringReplace($sAddData, $sChunkSub, "") ; delete all but the TRUE one
                                                    EndIf
                                                Next
                                                $sSubmit = ""
                                            EndIf
                                        EndIf
                                    ElseIf $aInputIds[3][$j] = "radio" Then
                                        If $sPassedData = $aInputIds[2][$j] Then
                                            For $sChunkSub In StringSplit($sRadio, $sGrSep, 3) ; go tru all "radio" controls
                                                If StringInStr($sChunkSub, "--" & $sBoundary & @CRLF & $sCDisp & $aInputIds[1][$j] & '"' & @CRLF & @CRLF & $sPassedData & @CRLF) Then
                                                    $sAddData = StringRegExpReplace($sAddData, "(?i)\Q--" & $sBoundary & @CRLF & $sCDisp & $aInputIds[1][$j] & '"' & @CRLF & @CRLF & "\E" & "(.*?)" & @CRLF, "")
                                                    $sAddData = StringReplace($sAddData, "--" & $sBoundary & "--" & @CRLF, "")
                                                    $sAddData &= $sChunkSub & "--" & $sBoundary & "--" & @CRLF
                                                    $sRadio = StringRegExpReplace($sRadio, "(?i)\Q--" & $sBoundary & @CRLF & $sCDisp & $aInputIds[1][$j] & '"' & @CRLF & @CRLF & "\E(.*?)" & @CRLF & $sGrSep & "?", "")
                                                EndIf
                                            Next
                                        EndIf
                                    ElseIf $aInputIds[3][$j] = "checkbox" Then
                                        $sCheckBox = StringRegExpReplace($sCheckBox, "(?i)\Q--" & $sBoundary & @CRLF & _
                                                $sCDisp & $aInputIds[1][$j] & '"' & @CRLF & @CRLF & _
                                                $sPassedData & @CRLF & "\E" & $sGrSep & "*", "")
                                        If StringRight($sCheckBox, 1) = $sGrSep Then $sCheckBox = StringTrimRight($sCheckBox, 1)
                                    ElseIf $aInputIds[3][$j] = "button" Then
                                        $sButton = StringRegExpReplace($sButton, "(?i)\Q--" & $sBoundary & @CRLF & _
                                                $sCDisp & $aInputIds[1][$j] & '"' & @CRLF & @CRLF & _
                                                $sPassedData & @CRLF & "\E" & $sGrSep & "*", "")
                                        If StringRight($sButton, 1) = $sGrSep Then $sButton = StringTrimRight($sButton, 1)
                                    Else
                                        $sAddData = StringReplace($sAddData, _
                                                $sCDisp & $aInputIds[1][$j] & '"' & @CRLF & @CRLF & $aInputIds[2][$j] & @CRLF, _
                                                $sCDisp & $aInputIds[1][$j] & '"' & @CRLF & @CRLF & $sPassedData & @CRLF)
                                        $iNumRepl = @extended
                                        If $iNumRepl > 1 Then ; equalize ; TODO: remove duplicates
                                            $sAddData = StringRegExpReplace($sAddData, '(?si)\Q--' & $sBoundary & @CRLF & $sCDisp & $aInputIds[1][$j] & '"' & '\E\r\n\r\n.*?\r\n', "", $iNumRepl - 1)
                                        EndIf
                                    EndIf
                                EndIf
                            Next
                        Else ; like getElementsByName
                            For $j = 0 To UBound($aInputIds, 2) - 1
                                If $aInputIds[1][$j] = $aSplit[1] And $aInputIds[3][$j] = "file" Then
                                    $sAddData = StringReplace($sAddData, _
                                            $sCDisp & $aSplit[1] & '"; filename=""' & @CRLF & @CRLF & $aInputIds[2][$j] & @CRLF, _
                                            __WinHttpFileContent($sAccept, $aInputIds[1][$j], $sPassedData, $sBoundary))
                                ElseIf $aInputIds[1][$j] = $aSplit[1] And $aInputIds[3][$j] = "submit" Then
                                    If $sPassedData = True Then ; if this "submit" is set to TRUE then
                                        If $sSubmit Then ; If not already processed; only the first is valid
                                            Local $fMDel = False
                                            For $sChunkSub In StringSplit($sSubmit, $sGrSep, 3) ; go tru all "submit" controls
                                                If $sChunkSub = "--" & $sBoundary & @CRLF & _
                                                        $sCDisp & $aInputIds[1][$j] & '"' & @CRLF & @CRLF & _
                                                        $aInputIds[2][$j] & @CRLF Then
                                                    If $fMDel Then $sAddData = StringReplace($sAddData, $sChunkSub, "", 1) ; Removing duplicates
                                                    $fMDel = True
                                                Else
                                                    $sAddData = StringReplace($sAddData, $sChunkSub, "") ; delete all but the TRUE one
                                                EndIf
                                            Next
                                            $sSubmit = ""
                                        EndIf
                                        ContinueLoop 2 ; process next parameter
                                    Else ; False means do nothing
                                        ContinueLoop 2 ; process next parameter
                                    EndIf
                                ElseIf $aInputIds[1][$j] = $aSplit[1] And $aInputIds[3][$j] = "radio" Then
                                    For $sChunkSub In StringSplit($sRadio, $sGrSep, 3) ; go tru all "radio" controls
                                        If StringInStr($sChunkSub, "--" & $sBoundary & @CRLF & $sCDisp & $aInputIds[1][$j] & '"' & @CRLF & @CRLF & $sPassedData & @CRLF) Then
                                            $sAddData = StringRegExpReplace($sAddData, "(?i)\Q--" & $sBoundary & @CRLF & $sCDisp & $aInputIds[1][$j] & '"' & @CRLF & @CRLF & "\E" & "(.*?)" & @CRLF, "")
                                            $sAddData = StringReplace($sAddData, "--" & $sBoundary & "--" & @CRLF, "")
                                            $sAddData &= $sChunkSub & "--" & $sBoundary & "--" & @CRLF
                                            $sRadio = StringRegExpReplace($sRadio, "(?i)\Q--" & $sBoundary & @CRLF & $sCDisp & $aInputIds[1][$j] & '"' & @CRLF & @CRLF & "\E(.*?)" & @CRLF & $sGrSep & "?", "")
                                        EndIf
                                    Next
                                    ContinueLoop 2 ; process next parameter
                                ElseIf $aInputIds[1][$j] = $aSplit[1] And $aInputIds[3][$j] = "checkbox" Then
                                    $sCheckBox = StringRegExpReplace($sCheckBox, "(?i)\Q--" & $sBoundary & @CRLF & _
                                            $sCDisp & $aInputIds[1][$j] & '"' & @CRLF & @CRLF & _
                                            $sPassedData & @CRLF & "\E" & $sGrSep & "*", "")
                                    If StringRight($sCheckBox, 1) = $sGrSep Then $sCheckBox = StringTrimRight($sCheckBox, 1)
                                    ContinueLoop 2 ; process next parameter
                                ElseIf $aInputIds[1][$j] = $aSplit[1] And $aInputIds[3][$j] = "button" Then
                                    $sButton = StringRegExpReplace($sButton, "(?i)\Q--" & $sBoundary & @CRLF & _
                                            $sCDisp & $aInputIds[1][$j] & '"' & @CRLF & @CRLF & _
                                            $sPassedData & @CRLF & "\E" & $sGrSep & "*", "")
                                    If StringRight($sButton, 1) = $sGrSep Then $sButton = StringTrimRight($sButton, 1)
                                    ContinueLoop 2 ; process next parameter
                                EndIf
                            Next
                            $sAddData = StringRegExpReplace($sAddData, '(?si)\Q' & $sCDisp & $aSplit[1] & '"' & '\E\r\n\r\n.*?\r\n', _
                                    $sCDisp & $aSplit[1] & '"' & @CRLF & @CRLF & StringReplace($sPassedData, "\", "\\") & @CRLF)
                            $iNumRepl = @extended
                            If $iNumRepl > 1 Then ; remove duplicates
                                $sAddData = StringRegExpReplace($sAddData, '(?si)\Q--' & $sBoundary & @CRLF & $sCDisp & $aSplit[1] & '"' & '\E\r\n\r\n.*?\r\n', "", $iNumRepl - 1)
                            EndIf
                        EndIf
                    Next
                EndIf
                __WinHttpFinalizeCtrls($sSubmit, $sRadio, $sCheckBox, $sButton, $sAddData, $sGrSep)
        EndSwitch
        ExitLoop
    Next
    ; Send
    If $fSend Then
        If $fVarForm Then
            $hInternet = _WinHttpConnect($hOpen, $sNewURL)
        Else
            If $sNewURL Then
                $hOpen = _WinHttpQueryOption($hInternet, $WINHTTP_OPTION_PARENT_HANDLE)
                _WinHttpCloseHandle($hInternet)
                $hInternet = _WinHttpConnect($hOpen, $sNewURL)
            EndIf
        EndIf
        If $iScheme = $INTERNET_SCHEME_HTTPS Then
            $hRequest = __WinHttpFormSend($hInternet, $sMethod, $sAction, $fMultiPart, $sBoundary, $sAddData, True, $sAdditionalHeaders)
        Else
            $hRequest = __WinHttpFormSend($hInternet, $sMethod, $sAction, $fMultiPart, $sBoundary, $sAddData, False, $sAdditionalHeaders)
            If _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_STATUS_CODE) > $HTTP_STATUS_BAD_REQUEST Then
                _WinHttpCloseHandle($hRequest)
                $hRequest = __WinHttpFormSend($hInternet, $sMethod, $sAction, $fMultiPart, $sBoundary, $sAddData, True, $sAdditionalHeaders) ; try adding $WINHTTP_FLAG_SECURE
            EndIf
        EndIf
        Local $sReturned = _WinHttpSimpleReadData($hRequest)
        If @error Then
            _WinHttpCloseHandle($hRequest)
            Return SetError(4, 0, "") ; either site is expiriencing problems or your connection
        EndIf
        _WinHttpCloseHandle($hRequest)
        Return $sReturned
    EndIf
    ; If here then there is no form on the page with specified attributes (name, id or index)
    Return SetError(3, 0, "")
EndFunc   ;==>_WinHttpSimpleFormFillSSL

Now I'm having problems using the function to set values for select fields in a form.

Simple example:

#include <WinHttp.au3>

Opt("MustDeclareVars", 1)

; 1. Open cs.tut.fi forms page (http://www.cs.tut.fi/~jkorpela/forms/navmenu.html)
; 2. Fill form on that page with these values/conditions:
; - form is to be identified by its name (nav2)
; - set -url- data to http://www.cs.tut.fi/~jkorpela/forms/
; - gather data (which is expected to return the source for http://www.cs.tut.fi/~jkorpela/forms/)

Global $aError[7] = ["", "No forms on the page", "Invalid form", "No forms with specified attributes on the page", "Connection problems", "Action is invalid", "Invalid session handle passed"]
Global $sURL = "http://www.cs.tut.fi/~jkorpela/forms/navmenu.html"
Global $aCracked = _WinHttpCrackUrl($sURL)
Global $hOpen = _WinHttpOpen() ; Initialize and get session handle
Global $hConnect = _WinHttpConnect($hOpen, $aCracked[2], $aCracked[3]) ; Get connection handle
Global $sRead = _WinHttpSimpleFormFill($hConnect, $aCracked[6], "name:nav2", "name:url", "http://www.cs.tut.fi/~jkorpela/forms/") ; Fill form on this page
If @error Then MsgBox(64, "Form Fill Error", $aError[@error])
_WinHttpCloseHandle($hConnect) ; Close connection handle
_WinHttpCloseHandle($hOpen) ; Close session handle now that's no longer needed

If $sRead Then
    MsgBox(64 + 262144, "Done!", "Will open returned page in your default browser now." & @CRLF & _
            "It should show sent data.")
    Global $sFileHTM = @ScriptDir & "\Form.htm"
    Global $hFileHTM = FileOpen($sFileHTM, 2)
    FileWrite($hFileHTM, $sRead)
    FileClose($hFileHTM)
    ShellExecuteWait($sFileHTM)
EndIf
Right now, I'm getting a "Connection problems" error.
Link to comment
Share on other sites

Well...since I didn't know there was a new latest version...no, I didn't :lol:

 

I've tried it now and the SSL problems are fixed, but I'm still getting the same error above with filling in select fields.  In another example I've tried, it just returns with the source for the page on which the form resides.

 

JavaScript:

function FormSubmit(objForm)
{
    var strColumnId, strType, objSearchColumn, intSelectedIndex;

    for ( strColumnId in arrSearchColumns)
    {
        objSearchColumn = arrSearchColumns[strColumnId];

        if (arrSearchColumns[strColumnId]['_bolFilter'] && arrSearchColumns[strColumnId]['_intFilterOrder'] == 1)
        {
            strType = parseInt(objSearchColumn['_strType']);

            if (strType == REPORT_COLUMN_SEARCH_SELECT)
            {
                intSelectedIndex = objForm.elements[strColumnId].selectedIndex;
            }
            else if (strType == REPORT_COLUMN_SEARCH_SELECT_MULTI)
            {
                intSelectedIndex = objForm.elements[strColumnId+'[]'].selectedIndex;
            }

            // If nothing is selected
            if (intSelectedIndex == -1)
            {
                // Send message to user
                alert('To run this report please select an option from: ' + objSearchColumn['_strAlias']);

                // Cancel form submission
                return false;
            }
        }
    }

    objForm.action = 'reportdisplay.php';
    objForm.submit();
}

Form:

<form name="report" method="post">

<input type="hidden" name="reportid" value="0004X8Z1">

<input type="hidden" name="reporturi" value="0004X8Z1">

<table border="0" cellpadding="2" cellspacing="1" class="ltGreydkGreyBorder" width="700">

<tr>

    <th class='dbmaintth'>FieldName</th>

    <th class='dbmaintth'>OP</th>

    <th class='dbmaintth'>Value</th>

</tr>





    

        

        <tr>

            <th class="coloredRightLabel" valign="top">OCN

                            <img src="/images/iconPrimaryKey.gif">

                        </th>



            

                

                <td>&nbsp;</td>

                <td class="bodyText">

                <table border="0">

                    <tr>

                        <td rowspan="2" id="tdOCN">

                            <select id="T0NO" name="T0NO[]" multiple="multiple" size="5" class="SelectBox" onkeypress="SelectKeyPressEvent(this)" onChange="isAllSelected(this); FilterOnChange(this, true)">

                                                            <option label="2060" value="2060" selected="selected">2060</option>



                                                        </select>

                        </td>

                        <td valign="top" width="100px">

                            <div id="hrefT0NO">

                                <a href="#" class="noLink" onClick="SelectAll(document.getElementById('T0NO'));">

                                    <img id="iconCheckT0NO" src="/images/iconUnCheck.gif" border="0"/><span id="SelectAllT0NO">Select All</span></a><br/>

                                                                    

                        </div>

                        </td>

                    </tr>

                    <tr>

                        <td valign="bottom">

                                                    <a href="javascript: document.forms.report.submit()" id="refreshT0NO"> <img src="/images/refresh.gif" border="0"/> Refresh</a>

                                                </td>

                    </tr>

                </table>



                        

        </tr>



    



    

        

                

        <tr>

            <th class="coloredRightLabel" valign="top">Distribution Dates </th>

            <td>&nbsp;</td>

            <td align="left">

                <select name="RGlzdHJpYnV0aW9uIERhdGVz[0]" class="SelectBox">

<option></option>

                <option label="2013-07-12" value="2013-07-12">2013-07-12</option>

<option label="2013-06-14" value="2013-06-14">2013-06-14</option>

<option label="2013-05-14" value="2013-05-14">2013-05-14</option>

<option label="2013-04-12" value="2013-04-12">2013-04-12</option>

<option label="2013-03-14" value="2013-03-14">2013-03-14</option>

<option label="2013-02-14" value="2013-02-14">2013-02-14</option>

<option label="2013-01-14" value="2013-01-14">2013-01-14</option>

<option label="2012-12-14" value="2012-12-14">2012-12-14</option>

<option label="2012-11-14" value="2012-11-14">2012-11-14</option>

<option label="2012-10-12" value="2012-10-12">2012-10-12</option>

<option label="2012-09-14" value="2012-09-14">2012-09-14</option>

<option label="2012-08-14" value="2012-08-14">2012-08-14</option>

<option label="2012-07-13" value="2012-07-13">2012-07-13</option>

<option label="2012-06-14" value="2012-06-14">2012-06-14</option>

<option label="2012-05-14" value="2012-05-14">2012-05-14</option>

<option label="2012-04-13" value="2012-04-13">2012-04-13</option>

<option label="2012-03-14" value="2012-03-14">2012-03-14</option>

<option label="2012-02-14" value="2012-02-14">2012-02-14</option>

<option label="2012-01-13" value="2012-01-13">2012-01-13</option>

<option label="2011-12-14" value="2011-12-14">2011-12-14</option>

<option label="2011-11-14" value="2011-11-14">2011-11-14</option>

<option label="2011-10-14" value="2011-10-14">2011-10-14</option>

<option label="2011-09-14" value="2011-09-14">2011-09-14</option>

<option label="2011-08-12" value="2011-08-12">2011-08-12</option>

<option label="2011-07-14" value="2011-07-14">2011-07-14</option>

<option label="2011-06-14" value="2011-06-14">2011-06-14</option>

<option label="2011-05-13" value="2011-05-13">2011-05-13</option>

<option label="2011-04-14" value="2011-04-14">2011-04-14</option>

<option label="2011-03-14" value="2011-03-14">2011-03-14</option>

<option label="2011-02-14" value="2011-02-14">2011-02-14</option>

<option label="2011-01-14" value="2011-01-14">2011-01-14</option>

<option label="2010-12-14" value="2010-12-14">2010-12-14</option>

<option label="2010-11-12" value="2010-11-12">2010-11-12</option>

<option label="2010-10-14" value="2010-10-14">2010-10-14</option>

<option label="2010-09-14" value="2010-09-14">2010-09-14</option>

<option label="2010-08-13" value="2010-08-13">2010-08-13</option>

<option label="2010-07-14" value="2010-07-14">2010-07-14</option>

<option label="2010-06-14" value="2010-06-14">2010-06-14</option>

<option label="2010-05-14" value="2010-05-14">2010-05-14</option>

<option label="2010-04-14" value="2010-04-14">2010-04-14</option>

<option label="2010-03-12" value="2010-03-12">2010-03-12</option>

<option label="2010-02-12" value="2010-02-12">2010-02-12</option>

<option label="2010-01-14" value="2010-01-14">2010-01-14</option>

<option label="2009-12-14" value="2009-12-14">2009-12-14</option>

<option label="2009-11-13" value="2009-11-13">2009-11-13</option>

<option label="2009-10-14" value="2009-10-14">2009-10-14</option>

<option label="2009-09-14" value="2009-09-14">2009-09-14</option>

<option label="2009-08-14" value="2009-08-14">2009-08-14</option>

<option label="2009-07-14" value="2009-07-14">2009-07-14</option>

<option label="2009-06-12" value="2009-06-12">2009-06-12</option>

<option label="2009-05-14" value="2009-05-14">2009-05-14</option>

<option label="2009-04-14" value="2009-04-14">2009-04-14</option>

<option label="2009-03-13" value="2009-03-13">2009-03-13</option>

<option label="2009-02-13" value="2009-02-13">2009-02-13</option>

<option label="2009-01-14" value="2009-01-14">2009-01-14</option>

<option label="2008-12-12" value="2008-12-12">2008-12-12</option>

<option label="2008-11-14" value="2008-11-14">2008-11-14</option>

<option label="2008-10-14" value="2008-10-14">2008-10-14</option>

<option label="2008-09-12" value="2008-09-12">2008-09-12</option>

<option label="2008-08-14" value="2008-08-14">2008-08-14</option>

<option label="2008-07-14" value="2008-07-14">2008-07-14</option>

<option label="2008-06-13" value="2008-06-13">2008-06-13</option>

<option label="2008-05-13" value="2008-05-13">2008-05-13</option>

<option label="2008-04-14" value="2008-04-14">2008-04-14</option>

<option label="2008-03-13" value="2008-03-13">2008-03-13</option>

<option label="2008-02-14" value="2008-02-14">2008-02-14</option>

<option label="2008-01-14" value="2008-01-14">2008-01-14</option>

<option label="2007-12-13" value="2007-12-13">2007-12-13</option>

<option label="2007-11-13" value="2007-11-13">2007-11-13</option>

<option label="2007-10-12" value="2007-10-12">2007-10-12</option>

<option label="2007-09-13" value="2007-09-13">2007-09-13</option>

<option label="2007-08-23" value="2007-08-23">2007-08-23</option>

<option label="2007-08-14" value="2007-08-14">2007-08-14</option>

<option label="2007-07-11" value="2007-07-11">2007-07-11</option>



                </select>



                &nbsp;To&nbsp;



                <select name="RGlzdHJpYnV0aW9uIERhdGVz[1]" class="SelectBox">

<option></option>

                <option label="2013-07-12" value="2013-07-12">2013-07-12</option>

<option label="2013-06-14" value="2013-06-14">2013-06-14</option>

<option label="2013-05-14" value="2013-05-14">2013-05-14</option>

<option label="2013-04-12" value="2013-04-12">2013-04-12</option>

<option label="2013-03-14" value="2013-03-14">2013-03-14</option>

<option label="2013-02-14" value="2013-02-14">2013-02-14</option>

<option label="2013-01-14" value="2013-01-14">2013-01-14</option>

<option label="2012-12-14" value="2012-12-14">2012-12-14</option>

<option label="2012-11-14" value="2012-11-14">2012-11-14</option>

<option label="2012-10-12" value="2012-10-12">2012-10-12</option>

<option label="2012-09-14" value="2012-09-14">2012-09-14</option>

<option label="2012-08-14" value="2012-08-14">2012-08-14</option>

<option label="2012-07-13" value="2012-07-13">2012-07-13</option>

<option label="2012-06-14" value="2012-06-14">2012-06-14</option>

<option label="2012-05-14" value="2012-05-14">2012-05-14</option>

<option label="2012-04-13" value="2012-04-13">2012-04-13</option>

<option label="2012-03-14" value="2012-03-14">2012-03-14</option>

<option label="2012-02-14" value="2012-02-14">2012-02-14</option>

<option label="2012-01-13" value="2012-01-13">2012-01-13</option>

<option label="2011-12-14" value="2011-12-14">2011-12-14</option>

<option label="2011-11-14" value="2011-11-14">2011-11-14</option>

<option label="2011-10-14" value="2011-10-14">2011-10-14</option>

<option label="2011-09-14" value="2011-09-14">2011-09-14</option>

<option label="2011-08-12" value="2011-08-12">2011-08-12</option>

<option label="2011-07-14" value="2011-07-14">2011-07-14</option>

<option label="2011-06-14" value="2011-06-14">2011-06-14</option>

<option label="2011-05-13" value="2011-05-13">2011-05-13</option>

<option label="2011-04-14" value="2011-04-14">2011-04-14</option>

<option label="2011-03-14" value="2011-03-14">2011-03-14</option>

<option label="2011-02-14" value="2011-02-14">2011-02-14</option>

<option label="2011-01-14" value="2011-01-14">2011-01-14</option>

<option label="2010-12-14" value="2010-12-14">2010-12-14</option>

<option label="2010-11-12" value="2010-11-12">2010-11-12</option>

<option label="2010-10-14" value="2010-10-14">2010-10-14</option>

<option label="2010-09-14" value="2010-09-14">2010-09-14</option>

<option label="2010-08-13" value="2010-08-13">2010-08-13</option>

<option label="2010-07-14" value="2010-07-14">2010-07-14</option>

<option label="2010-06-14" value="2010-06-14">2010-06-14</option>

<option label="2010-05-14" value="2010-05-14">2010-05-14</option>

<option label="2010-04-14" value="2010-04-14">2010-04-14</option>

<option label="2010-03-12" value="2010-03-12">2010-03-12</option>

<option label="2010-02-12" value="2010-02-12">2010-02-12</option>

<option label="2010-01-14" value="2010-01-14">2010-01-14</option>

<option label="2009-12-14" value="2009-12-14">2009-12-14</option>

<option label="2009-11-13" value="2009-11-13">2009-11-13</option>

<option label="2009-10-14" value="2009-10-14">2009-10-14</option>

<option label="2009-09-14" value="2009-09-14">2009-09-14</option>

<option label="2009-08-14" value="2009-08-14">2009-08-14</option>

<option label="2009-07-14" value="2009-07-14">2009-07-14</option>

<option label="2009-06-12" value="2009-06-12">2009-06-12</option>

<option label="2009-05-14" value="2009-05-14">2009-05-14</option>

<option label="2009-04-14" value="2009-04-14">2009-04-14</option>

<option label="2009-03-13" value="2009-03-13">2009-03-13</option>

<option label="2009-02-13" value="2009-02-13">2009-02-13</option>

<option label="2009-01-14" value="2009-01-14">2009-01-14</option>

<option label="2008-12-12" value="2008-12-12">2008-12-12</option>

<option label="2008-11-14" value="2008-11-14">2008-11-14</option>

<option label="2008-10-14" value="2008-10-14">2008-10-14</option>

<option label="2008-09-12" value="2008-09-12">2008-09-12</option>

<option label="2008-08-14" value="2008-08-14">2008-08-14</option>

<option label="2008-07-14" value="2008-07-14">2008-07-14</option>

<option label="2008-06-13" value="2008-06-13">2008-06-13</option>

<option label="2008-05-13" value="2008-05-13">2008-05-13</option>

<option label="2008-04-14" value="2008-04-14">2008-04-14</option>

<option label="2008-03-13" value="2008-03-13">2008-03-13</option>

<option label="2008-02-14" value="2008-02-14">2008-02-14</option>

<option label="2008-01-14" value="2008-01-14">2008-01-14</option>

<option label="2007-12-13" value="2007-12-13">2007-12-13</option>

<option label="2007-11-13" value="2007-11-13">2007-11-13</option>

<option label="2007-10-12" value="2007-10-12">2007-10-12</option>

<option label="2007-09-13" value="2007-09-13">2007-09-13</option>

<option label="2007-08-23" value="2007-08-23">2007-08-23</option>

<option label="2007-08-14" value="2007-08-14">2007-08-14</option>

<option label="2007-07-11" value="2007-07-11">2007-07-11</option>



                </select>

                                            </td>

        </tr>



    



    









<tr>

    <td colspan="3">&nbsp;<br /></td>

</tr>

<tr>

    <td colspan="3" align="center">

        <input type="button" id="initsearch" name="initsearch" value="Run Report &gt;&gt;" class="ltGreydkGreyBorder"

onclick="javascript: FormSubmit(this.form)"/>

    </td>

</tr>



</table>



</form>

What I've tried:

$hRequest = _WinHttpOpenRequest($hConnect, Default, "/webtrack/reportsearch.php?templateId=0004X8Z1", Default, Default, Default, $WINHTTP_FLAG_SECURE) ; LEC Distribution
_WinHttpAddRequestHeaders($hRequest, "Accept: text/html;q=0.9,text/plain;q=0.8,*/*;q=0.5")
_WinHttpSendRequest($hRequest)
_WinHttpReceiveResponse($hRequest)
$sHTML = ""
If _WinHttpQueryDataAvailable($hRequest) Then
    Do
        $sHTML &= _WinHttpReadData($hRequest)
    Until @error
EndIf
_WinHttpCloseHandle($hRequest)
Global $aSelect = StringRegExp($sHTML, '<select name=["](\w+\[\d\])["] class=["]SelectBox["]>', 3)
Global $aDate = StringRegExp($sHTML, '<option label=["](' & @YEAR & '-' & StringFormat("%02d", @MON) & '-' & '\d{2})["] value=["]\1["]>', 3)
$sHTML = _WinHttpSimpleFormFill($hConnect, "/webtrack/reportsearch.php?templateId=0004X8Z1", "name:report", "T0NO", "2060", $aSelect[0], $aDate[0], $aSelect[1], $aDate[1], "initsearch", True)
If $sHTML Then
    Global $hFileHTM, $sFileHTM = @ScriptDir & "\Form.htm"
    SplashOff()
    MsgBox(64 + 262144, "BSG", "Will open returned page in your default browser now." & @CRLF & _
            "It should show sent data.")
    $hFileHTM = FileOpen($sFileHTM, 2)
    FileWrite($hFileHTM, $sHTML)
    FileClose($hFileHTM)
    ShellExecuteWait($sFileHTM)
EndIf
Link to comment
Share on other sites

OK, I've gotten everything I need, though I didn't quite do it as expected. I ended up looking at the HTTP headers using LiveHTTPHeaders in FireFox, as someone else here had done. Fortunately, it gave me everything I needed to submit requests, instead of having to fill more forms. So the only form I had to fill out was the first form to log in. :-D

I'd still like to be able to submit forms with select (dropdown) fields if anyone has any good examples.

Link to comment
Share on other sites

That's great, I'm glad you figured out the way.

As for dropdowns, the jkorpela example from the above is the example where there is no real form. They are saying that on the linked page. That example shows how jscript can be used to process the input. If you click on their "submit" (in yout browser) you'll see that dropdown isn't used at all.

♡♡♡

.

eMyvnE

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...