Jump to content

[Help] WinHTTP Proxy with login doesn't work on HTTPS


Recommended Posts

Hello to the AutoIt Community - I'm here because I need help with WinHTTP:

I coded a program which works with _WinHttpSimpleRequest and _WinHttpSimpleSSLRequest. But now I am working with proxies which require a username and password (ip:port:username:pw) but I can't get it to work. I already accomplished a working connection with HTTP but HTTPS won't work and I get the response "access dined". I would be happy if anybody could help me out.

Here my code so far

;works
$hConnect = _WinHttpConnect($hInternet, "autoit.de")
Set_Proxy("ip:port")
_WinHttpSimpleRequest2($hConnect, "GET")


;doesn't work
$hConnect = _WinHttpConnect($hInternet, "google.de")
Set_Proxy("ip:port")
_WinHttpSimpleSSLRequest2($hConnect, "GET")


Func _WinHttpSimpleRequest2($hConnect, $sType = Default, $sPath = Default, $sReferrer = Default, $sData = Default, $sHeader = Default, $fGetHeaders = Default, $iMode = Default)
_WinHttpSetOption($hConnect, $WINHTTP_OPTION_PROXY_USERNAME, "user")
_WinHttpSetOption($hConnect, $WINHTTP_OPTION_PROXY_PASSWORD, "pw")
$source = ""
$hRequest = _WinHttpOpenRequest($hConnect, $sType, $sPath, Default, $sReferrer)
If $hRequest Then
; Set password here
_WinHttpSetCredentials($hRequest, $WINHTTP_AUTH_TARGET_PROXY, $WINHTTP_AUTH_SCHEME_BASIC, "user", "pw")
$sHeader = "Content-Type: application/x-www-form-urlencoded" & @CRLF

If _WinHttpSendRequest($hRequest, $sHeader, $sData) Then
_WinHttpReceiveResponse($hRequest)
$source = _WinHttpSimpleReadData($hRequest)
EndIf
_WinHttpCloseHandle($hRequest)
EndIf
Return $source
EndFunc

Func _WinHttpSimpleSSLRequest2($hConnect, $sType = Default, $sPath = Default, $sReferrer = Default, $sData = Default, $sHeader = Default, $fGetHeaders = Default, $iMode = Default)
$source = ""
_WinHttpSetOption($hConnect, $WINHTTP_OPTION_PROXY_USERNAME, "user")
_WinHttpSetOption($hConnect, $WINHTTP_OPTION_PROXY_PASSWORD, "pw")

$hRequest = _WinHttpOpenRequest($hConnect, $sType, $sPath, Default, $sReferrer, Default, BitOR($WINHTTP_FLAG_SECURE, $WINHTTP_FLAG_ESCAPE_DISABLE))
If $hRequest Then
; Set password here
_WinHttpSetCredentials($hRequest, $WINHTTP_AUTH_TARGET_PROXY, $WINHTTP_AUTH_SCHEME_BASIC, "user", "pw")
$sHeader = "Content-Type: application/x-www-form-urlencoded" & @CRLF

If _WinHttpSendRequest($hRequest, $sHeader, $sData) Then
_WinHttpReceiveResponse($hRequest)
$source = _WinHttpSimpleReadData($hRequest)
EndIf
_WinHttpCloseHandle($hRequest)
EndIf

Return $source
EndFunc
Link to comment
Share on other sites

  • 2 months later...

try

_WinHttpSimpleSSLRequest2($hConnect, "GET")

Edited by DiOgO

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there'sĀ InetReadĀ and WinHTTP, way better
happy.png

Link to comment
Share on other sites

You'll have to connect to the https port if you want to send ssl requests. The helpfile should contain examples.

*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

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