@@ -153,19 +153,25 @@ EndFunc
153
153
; Link ..........: http://msdn.microsoft.com/en-us/library/aa384091.aspx
154
154
; ============================================================================================
155
155
Func _WinHttpConnect($hSession , $sServerName , $iServerPort = Default )
156
- Local $aURL = _WinHttpCrackUrl($sServerName )
156
+ Local $aURL = _WinHttpCrackUrl($sServerName ), $iScheme = 0
157
157
If @error Then
158
158
__WinHttpDefault($iServerPort , $INTERNET_DEFAULT_PORT )
159
159
Else
160
160
$sServerName = $aURL [2 ]
161
161
$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
162
167
EndIf
163
168
Local $aCall = DllCall ($hWINHTTPDLL__WINHTTP , " handle" , " WinHttpConnect" , _
164
169
" handle" , $hSession , _
165
170
" wstr" , $sServerName , _
166
171
" dword" , $iServerPort , _
167
172
" dword" , 0 )
168
173
If @error Or Not $aCall [0 ] Then Return SetError (1 , 0 , 0 )
174
+ _WinHttpSetOption($aCall [0 ], $WINHTTP_OPTION_CONTEXT_VALUE , $iScheme )
169
175
Return $aCall [0 ]
170
176
EndFunc
171
177
@@ -1137,10 +1143,21 @@ Func _WinHttpSimpleFormFill(ByRef $hInternet, $sActionPage = Default, $sFormId =
1137
1143
$hOpen = $sActionPage
1138
1144
$fVarForm = True
1139
1145
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
1144
1161
EndIf
1145
1162
EndIf
1146
1163
$sHTML = StringRegExpReplace ($sHTML , " (?s)<!--.*?-->" , " " ) ; removing comments
0 commit comments