Jump to content

WinHTTP Proxyauth


Recommended Posts

Hey ! I am trying to use some private proxies on WInHTTP requests and I keep getting an error like "Sorry, you are not currently allowed to request http://www.ip-adress.com from this cache until you have authenticated yourself." . I use this code:

#include<WinHTTP.au3>
#include<WinApi.au3>
Global Const $tagWINHTTP_PROXY_INFO = "DWORD  dwAccessType;ptr lpszProxy;ptr lpszProxyBypass;"

Func _WinHttpProxyInfoCreate($dwAccessType, $sProxy, $sProxyBypass)
    Local $tWINHTTP_PROXY_INFO[2] = [DllStructCreate($tagWINHTTP_PROXY_INFO), DllStructCreate('wchar proxychars[' & StringLen($sProxy)+1 & ']; wchar proxybypasschars[' & StringLen($sProxyBypass)+1 & ']')]
    DllStructSetData($tWINHTTP_PROXY_INFO[0], "dwAccessType", $dwAccessType)
    If StringLen($sProxy) Then DllStructSetData($tWINHTTP_PROXY_INFO[0], "lpszProxy", DllStructGetPtr($tWINHTTP_PROXY_INFO[1], 'proxychars'))
    If StringLen($sProxyByPass) Then DllStructSetData($tWINHTTP_PROXY_INFO[0], "lpszProxyBypass", DllStructGetPtr($tWINHTTP_PROXY_INFO[1], 'proxybypasschars'))
    DllStructSetData($tWINHTTP_PROXY_INFO[1], "proxychars", $sProxy)
    DllStructSetData($tWINHTTP_PROXY_INFO[1], "proxybypasschars", $sProxyBypass)
    Return $tWINHTTP_PROXY_INFO
EndFunc

$hInternet = _WinHttpOpen()

$hConnect = _WinHttpConnect($hInternet, "ip-adress.com")
$standard = _WinHttpSimpleRequest($hConnect, "GET", "/get_html.php")
_WinHttpCloseHandle($hConnect)


$tProxyInfo = _WinHttpProxyInfoCreate($WINHTTP_ACCESS_TYPE_NAMED_PROXY, "xx.xxx.xx.xx:xxxxx", "")
_WinHttpSetOption($hInternet, $WINHTTP_OPTION_PROXY, $tProxyInfo[0])

$hConnect = _WinHttpConnect($hInternet, "ip-adress.com")

_WinHttpSetOption($hInternet, $WINHTTP_OPTION_PROXY_USERNAME, "user")
_WinHttpSetOption($hInternet, $WINHTTP_OPTION_PROXY_PASSWORD, "pass")

$mit_proxy = ""
$hRequest = _WinHttpOpenRequest($hConnect, "GET")
If $hRequest Then
    ; Set password here
    _WinHttpSetCredentials($hRequest, $WINHTTP_AUTH_TARGET_PROXY, $WINHTTP_AUTH_SCHEME_BASIC, "user", "pass")
    If _WinHttpSendRequest($hRequest) Then
        _WinHttpReceiveResponse($hRequest)
        $mit_proxy = _WinHttpSimpleReadData($hRequest)
        msgbox(0,"",$mit_proxy)

    EndIf
    _WinHttpCloseHandle($hRequest)
EndIf

_WinHttpCloseHandle($hConnect)

I'm using an working private proxy. Can anyone help me to get this working ? Thank you, Luke !

Edited by quarqo
Link to comment
Share on other sites

I don't use WinHTTP UDF but I use directly ObjCreate("winhttp.winhttprequest.5.1")

something like this

$ini_proxy = '10.10.10.230:8000'
$ini_proxy_name = 'name'
$ini_proxy_passw = 'password'

Const $HTTPREQUEST_PROXYSETTING_DEFAULT = 0
Const $HTTPREQUEST_PROXYSETTING_PRECONFIG = 0
Const $HTTPREQUEST_PROXYSETTING_DIRECT = 1
Const $HTTPREQUEST_PROXYSETTING_PROXY = 2
Const $HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
Const $HTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1

$o_http = ObjCreate("winhttp.winhttprequest.5.1")

If $ini_proxy <> '' Then
    $o_http.SetProxy($HTTPREQUEST_PROXYSETTING_PROXY, $ini_proxy, "")
    If $ini_proxy_name <> '' Then
        $o_http.SetCredentials($ini_proxy_name, $ini_proxy_passw, $HTTPREQUEST_SETCREDENTIALS_FOR_PROXY)
    EndIf
EndIf

$p1 = "value1"
$p2 = "value2"
$data = "param1=" & $p1 & "&param2=" & $p2

$o_HTTP.Open('GET', 'http://www.something.com', False)
$o_HTTP.SetRequestHeader('Content-Type','application/x-www-form-urlencoded')
$o_HTTP.SetRequestHeader('Content-Length',StringLen($data))
$o_HTTP.Send($data)

ConsoleWrite($o_HTTP.Responsetext & @CRLF)
Link to comment
Share on other sites

I don't use WinHTTP UDF but I use directly ObjCreate("winhttp.winhttprequest.5.1")

something like this

$ini_proxy = '10.10.10.230:8000'
$ini_proxy_name = 'name'
$ini_proxy_passw = 'password'

Const $HTTPREQUEST_PROXYSETTING_DEFAULT = 0
Const $HTTPREQUEST_PROXYSETTING_PRECONFIG = 0
Const $HTTPREQUEST_PROXYSETTING_DIRECT = 1
Const $HTTPREQUEST_PROXYSETTING_PROXY = 2
Const $HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
Const $HTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1

$o_http = ObjCreate("winhttp.winhttprequest.5.1")

If $ini_proxy <> '' Then
    $o_http.SetProxy($HTTPREQUEST_PROXYSETTING_PROXY, $ini_proxy, "")
    If $ini_proxy_name <> '' Then
        $o_http.SetCredentials($ini_proxy_name, $ini_proxy_passw, $HTTPREQUEST_SETCREDENTIALS_FOR_PROXY)
    EndIf
EndIf

$p1 = "value1"
$p2 = "value2"
$data = "param1=" & $p1 & "&param2=" & $p2

$o_HTTP.Open('GET', 'http://www.something.com', False)
$o_HTTP.SetRequestHeader('Content-Type','application/x-www-form-urlencoded')
$o_HTTP.SetRequestHeader('Content-Length',StringLen($data))
$o_HTTP.Send($data)

ConsoleWrite($o_HTTP.Responsetext & @CRLF)

Thank you for help, i really appreciate ! But there is any way to do this with WinHTTP UDF ?
Link to comment
Share on other sites

Here I wrote what you have to do for a proxy with a password:

*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

Here I wrote what you have to do for a proxy with a password:

http://autoitscript.com/forum/topic/8413...unctions/page__view__findpost_

Thank you but still not working ! The only website i can access using your script is whatismyipaddress.com and yes it says that i'm using an proxy. The problem is that i can't access any other websites, like google, facebook, etc. Im still getting this error "

Cache Access Denied.

Sorry, you are not currently allowed to request http://www.facebook.com/ from this cache until you have authenticated yourself.

" ( same on any other website). What cause this error ? Thanks !

Link to comment
Share on other sites

you have to set the password for each request you are making.

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