I would like to call the Windows C ++ function WinHttpGetProxyForUrl from Python - can this be done?

Microsoft provides a method as part of WinHTTP that allows the user to determine which proxy should be used for any given URL. It is called WinHttpGetProxyForUrl .

Unfortunately, I program in python, so I can’t access this function directly - I can use Win32COM to call any Microsoft service using the COM interface.

So, is there a way to access this function from Python? As an additional problem, I cannot add anything but Python to the project. This means that, however, it is not possible to add corrections in C # or C ++.

I am running Python2.4.4 with Win32 extensions on Windows XP.

Update 0:

This is what I have so far:

import win32inet
import pprint
hinternet = win32inet.InternetOpen("foo 1.0", 0, "", "", 0)
# Does not work!!!
proxy = win32inet.WinHttpGetProxyForUrl( hinternet, u"http://www.foo.com", 0  )

Obviously, the last line is incorrect, however I do not see any documents or examples on the right path!

Update 1:

I am going to ask this again as a new question, since now we are talking about win32com .

+1
source share
2 answers

ctypes WinHttp.dll, DLL, "WinHttpGetProxyForUrl". ' HINTERNET, , , ctypes DLL, HINTERNET, WinHttpGetProxyForUrl, , , , .

ctypes @http://docs.python.org/library/ctypes.html

import ctypes

winHttp = ctypes.windll.LoadLibrary("Winhttp.dll")

WINHTTP_ACCESS_TYPE_DEFAULT_PROXY=0
WINHTTP_NO_PROXY_NAME=WINHTTP_NO_PROXY_BYPASS=0
WINHTTP_FLAG_ASYNC=0x10000000
# http://msdn.microsoft.com/en-us/library/aa384098(VS.85).aspx
HINTERNET = winHttp.WinHttpOpen("PyWin32", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, WINHTTP_FLAG_ASYNC)

print HINTERNET
+1

ActiveState: WINHTTP_AUTOPROXY_OPTIONS , WinHttpGetProxyForUrl win32inet Win32. SourceForge , , , .

" 0" :

WINHTTP_AUTOPROXY_OPTIONS WINHTTP_PROXY_INFO, MSDN: WinHttpGetProxyForUrl.

+1

Source: https://habr.com/ru/post/1711804/


All Articles