Skip to content

Commit 4e8824c

Browse files
committed
Added: Additional logic for form filling function.
1 parent 865d405 commit 4e8824c

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

WinHttp.au3

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ Func _WinHttpSimpleFormFill(ByRef $hInternet, $sActionPage = Default, $sFormId =
11391139
EndIf
11401140
EndIf
11411141
; Get page source
1142-
Local $hOpen, $sHTML, $fVarForm, $iScheme = $INTERNET_SCHEME_HTTP
1142+
Local $hOpen, $aHTML, $sHTML, $sURL, $fVarForm, $iScheme = $INTERNET_SCHEME_HTTP
11431143
If IsString($hInternet) Then ; $hInternet is page source
11441144
$sHTML = $hInternet
11451145
If _WinHttpQueryOption($sActionPage, $WINHTTP_OPTION_HANDLE_TYPE) <> $WINHTTP_HANDLE_TYPE_SESSION Then Return SetError(6, 0, "")
@@ -1149,19 +1149,23 @@ Func _WinHttpSimpleFormFill(ByRef $hInternet, $sActionPage = Default, $sFormId =
11491149
$iScheme = _WinHttpQueryOption($hInternet, $WINHTTP_OPTION_CONTEXT_VALUE); read internet scheme from the connection handle
11501150
Local $sAccpt = "Accept: text/html;q=0.9,text/plain;q=0.8,*/*;q=0.5"
11511151
If $iScheme = $INTERNET_SCHEME_HTTPS Then
1152-
$sHTML = _WinHttpSimpleSSLRequest($hInternet, Default, $sActionPage, Default, Default, $sAccpt, Default, Default, $sCredName, $sCredPass, $iIgnoreCertErr)
1152+
$aHTML = _WinHttpSimpleSSLRequest($hInternet, Default, $sActionPage, Default, Default, $sAccpt, 1, Default, $sCredName, $sCredPass, $iIgnoreCertErr)
11531153
ElseIf $iScheme = $INTERNET_SCHEME_HTTP Then
1154-
$sHTML = _WinHttpSimpleRequest($hInternet, Default, $sActionPage, Default, Default, $sAccpt, Default, Default, $sCredName, $sCredPass)
1154+
$aHTML = _WinHttpSimpleRequest($hInternet, Default, $sActionPage, Default, Default, $sAccpt, 1, Default, $sCredName, $sCredPass)
11551155
Else
11561156
; Try both http and https scheme and deduct the right one besed on response
1157-
$sHTML = _WinHttpSimpleRequest($hInternet, Default, $sActionPage, Default, Default, $sAccpt, Default, Default, $sCredName, $sCredPass)
1157+
$aHTML = _WinHttpSimpleRequest($hInternet, Default, $sActionPage, Default, Default, $sAccpt, 1, Default, $sCredName, $sCredPass)
11581158
If @error Or @extended >= $HTTP_STATUS_BAD_REQUEST Then
1159-
$sHTML = _WinHttpSimpleSSLRequest($hInternet, Default, $sActionPage, Default, Default, $sAccpt, Default, Default, $sCredName, $sCredPass, $iIgnoreCertErr)
1159+
$aHTML = _WinHttpSimpleSSLRequest($hInternet, Default, $sActionPage, Default, Default, $sAccpt, 1, Default, $sCredName, $sCredPass, $iIgnoreCertErr)
11601160
$iScheme = $INTERNET_SCHEME_HTTPS
11611161
Else
11621162
$iScheme = $INTERNET_SCHEME_HTTP
11631163
EndIf
11641164
EndIf
1165+
If Not @error Then ; Error is checked after If...Then...Else block. Be careful before changing anything!
1166+
$sHTML = $aHTML[1]
1167+
$sURL = $aHTML[2]
1168+
EndIf
11651169
EndIf
11661170
$sHTML = StringRegExpReplace($sHTML, "(?s)<!--.*?-->", "") ; removing comments
11671171
$sHTML = StringRegExpReplace($sHTML, "(?s)<!\[CDATA\[.*?\]\]>", "") ; removing CDATA
@@ -1217,7 +1221,7 @@ Func _WinHttpSimpleFormFill(ByRef $hInternet, $sActionPage = Default, $sFormId =
12171221
; HTML5 allows for "formaction", "formenctype", "formmethod" submit-control attributes to be set. If such control is "clicked" then form's attributes needs updating/correcting
12181222
__WinHttpHTML5FormAttribs($aDtas, $aFlds, $iNumParams, $aInput, $sAction, $sEnctype, $sMethod)
12191223
; Workout correct URL, scheme, etc...
1220-
__WinHttpNormalizeActionURL($sActionPage, $sAction, $iScheme, $sNewURL, $sEnctype, $sMethod)
1224+
__WinHttpNormalizeActionURL($sActionPage, $sAction, $iScheme, $sNewURL, $sEnctype, $sMethod, $sURL)
12211225
If $fVarForm And Not $sNewURL Then Return SetError(5, 0, "") ; "action" must have URL specified
12221226
Local $aSplit, $sBoundary, $sPassedId, $sPassedData, $iNumRepl, $fMultiPart = False, $sSubmit, $sRadio, $sCheckBox, $sButton
12231227
Local $sGrSep = Chr(29)
@@ -2035,7 +2039,7 @@ Func __WinHttpHTMLDecode($vData)
20352039
Return StringReplace(StringReplace(StringReplace(StringReplace($vData, "&amp;", "&"), "&lt;", "<"), "&gt;", ">"), "&quot;", '"')
20362040
EndFunc
20372041

2038-
Func __WinHttpNormalizeActionURL($sActionPage, ByRef $sAction, ByRef $iScheme, ByRef $sNewURL, ByRef $sEnctype, ByRef $sMethod)
2042+
Func __WinHttpNormalizeActionURL($sActionPage, ByRef $sAction, ByRef $iScheme, ByRef $sNewURL, ByRef $sEnctype, ByRef $sMethod, $sURL = "")
20392043
Local $aCrackURL = _WinHttpCrackUrl($sAction)
20402044
If @error Then
20412045
If $sAction Then

0 commit comments

Comments
 (0)