Skip to content

Commit f39b973

Browse files
committed
Added: More code for HTTPS vs HTTP scheme detection algo.
1 parent 946834e commit f39b973

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

WinHttp.au3

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,25 @@ EndFunc
153153
; Link ..........: http://msdn.microsoft.com/en-us/library/aa384091.aspx
154154
;============================================================================================
155155
Func _WinHttpConnect($hSession, $sServerName, $iServerPort = Default)
156-
Local $aURL = _WinHttpCrackUrl($sServerName)
156+
Local $aURL = _WinHttpCrackUrl($sServerName), $iScheme = 0
157157
If @error Then
158158
__WinHttpDefault($iServerPort, $INTERNET_DEFAULT_PORT)
159159
Else
160160
$sServerName = $aURL[2]
161161
$iServerPort = $aURL[3]
162+
If $iServerPort = $INTERNET_DEFAULT_HTTPS_PORT Then
163+
$iScheme = $INTERNET_SCHEME_HTTPS
164+
ElseIf $iServerPort = $INTERNET_DEFAULT_HTTP_PORT Then
165+
$iScheme = $INTERNET_SCHEME_HTTP
166+
EndIf
162167
EndIf
163168
Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "handle", "WinHttpConnect", _
164169
"handle", $hSession, _
165170
"wstr", $sServerName, _
166171
"dword", $iServerPort, _
167172
"dword", 0)
168173
If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
174+
_WinHttpSetOption($aCall[0], $WINHTTP_OPTION_CONTEXT_VALUE, $iScheme)
169175
Return $aCall[0]
170176
EndFunc
171177

@@ -1137,10 +1143,21 @@ Func _WinHttpSimpleFormFill(ByRef $hInternet, $sActionPage = Default, $sFormId =
11371143
$hOpen = $sActionPage
11381144
$fVarForm = True
11391145
Else
1140-
$sHTML = _WinHttpSimpleRequest($hInternet, Default, $sActionPage, Default, Default, "Accept: text/html;q=0.9,text/plain;q=0.8,*/*;q=0.5", Default, Default, $sCredName, $sCredPass)
1141-
If @error Or @extended >= $HTTP_STATUS_BAD_REQUEST Then
1142-
$sHTML = _WinHttpSimpleSSLRequest($hInternet, Default, $sActionPage, Default, Default, "Accept: text/html;q=0.9,text/plain;q=0.8,*/*;q=0.5", Default, Default, $sCredName, $sCredPass)
1143-
$iScheme = $INTERNET_SCHEME_HTTPS
1146+
$iScheme = _WinHttpQueryOption($hInternet, $WINHTTP_OPTION_CONTEXT_VALUE); read internet scheme from the connection handle
1147+
Local $sAccpt = "Accept: text/html;q=0.9,text/plain;q=0.8,*/*;q=0.5"
1148+
If $iScheme = $INTERNET_SCHEME_HTTPS Then
1149+
$sHTML = _WinHttpSimpleSSLRequest($hInternet, Default, $sActionPage, Default, Default, $sAccpt, Default, Default, $sCredName, $sCredPass)
1150+
ElseIf $iScheme = $INTERNET_SCHEME_HTTP Then
1151+
$sHTML = _WinHttpSimpleRequest($hInternet, Default, $sActionPage, Default, Default, $sAccpt, Default, Default, $sCredName, $sCredPass)
1152+
Else
1153+
; Try both http and https scheme and deduct the right one besed on response
1154+
$sHTML = _WinHttpSimpleRequest($hInternet, Default, $sActionPage, Default, Default, $sAccpt, Default, Default, $sCredName, $sCredPass)
1155+
If @error Or @extended >= $HTTP_STATUS_BAD_REQUEST Then
1156+
$sHTML = _WinHttpSimpleSSLRequest($hInternet, Default, $sActionPage, Default, Default, $sAccpt, Default, Default, $sCredName, $sCredPass)
1157+
$iScheme = $INTERNET_SCHEME_HTTPS
1158+
Else
1159+
$iScheme = $INTERNET_SCHEME_HTTP
1160+
EndIf
11441161
EndIf
11451162
EndIf
11461163
$sHTML = StringRegExpReplace($sHTML, "(?s)<!--.*?-->", "") ; removing comments

0 commit comments

Comments
 (0)