Created
July 27, 2013 01:02
-
-
Save timerickson/6093211 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.InteropServices; | |
namespace ProxySetup | |
{ | |
public abstract class WinHttpProxyWin32 | |
{ | |
/// <summary> | |
/// WINHTTP_PROXY_INFO - structure supplied with WINHTTP_OPTION_PROXY to | |
/// get/set proxy information on a WinHttpOpen() handle | |
/// </summary> | |
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] | |
public struct WINHTTP_PROXY_INFO | |
{ | |
/// <summary> | |
/// see WINHTTP_ACCESS_* types | |
/// </summary> | |
public WINHTTP_ACCESS_TYPES dwAccessType; | |
/// <summary> | |
/// proxy server list | |
/// </summary> | |
public string lpszProxy; | |
/// <summary> | |
/// proxy bypass list | |
/// </summary> | |
public string lpszProxyBypass; | |
} | |
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] | |
public struct WINHTTP_AUTOPROXY_OPTIONS | |
{ | |
public uint dwFlags; | |
public uint dwAutoDetectFlags; | |
public IntPtr lpszAutoConfigUrl; | |
public IntPtr lpvReserved; | |
public uint dwReserved; | |
public bool fAutoLogonIfChallenged; | |
}; | |
[StructLayout(LayoutKind.Sequential)] | |
public struct WINHTTP_CURRENT_USER_IE_PROXY_CONFIG | |
{ | |
public bool fAutoDetect; | |
public IntPtr lpszAutoConfigUrl; | |
public IntPtr lpszProxy; | |
public IntPtr lpszProxyBypass; | |
}; | |
/// <summary> | |
/// WinHttpOpen dwAccessType values (also for WINHTTP_PROXY_INFO::dwAccessType) | |
/// </summary> | |
public enum WINHTTP_ACCESS_TYPES | |
{ | |
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY = 0, | |
WINHTTP_ACCESS_TYPE_NO_PROXY = 1, | |
WINHTTP_ACCESS_TYPE_NAMED_PROXY = 3 | |
} | |
public const string WINHTTP_NO_PROXY_NAME = null; | |
public const string WINHTTP_NO_PROXY_BYPASS = null; | |
[DllImport("winhttp.dll", CharSet = CharSet.Unicode, SetLastError = true)] | |
public static extern bool WinHttpSetDefaultProxyConfiguration(ref WINHTTP_PROXY_INFO info); | |
[DllImport("winhttp.dll", CharSet = CharSet.Unicode, SetLastError = true)] | |
public static extern bool WinHttpGetDefaultProxyConfiguration(ref WINHTTP_PROXY_INFO info); | |
//[DllImport("winhttp", CharSet = CharSet.Unicode, SetLastError = true)] | |
//private extern static System.IntPtr WinHttpOpen(string pwszUserAgent, uint dwAccessType, string pwszProxyName, string pwszProxyBypass, uint dwFlags); | |
//[DllImport("winhttp", CharSet = CharSet.Unicode, SetLastError = true)] | |
//private extern static bool WinHttpGetProxyForUrl(System.IntPtr hSession, string lpcwszUrl, ref WINHTTP_AUTOPROXY_OPTIONS pAutoProxyOptions, ref WINHTTP_PROXY_INFO pProxyInfo); | |
//[DllImport("winhttp")] | |
//private extern static bool WinHttpCloseHandle(System.IntPtr hInternet); | |
[DllImport("winhttp")] | |
private extern static bool WinHttpGetIEProxyConfigForCurrentUser(ref WINHTTP_CURRENT_USER_IE_PROXY_CONFIG pProxyConfig); | |
//[DllImport("winhttp", CharSet = CharSet.Unicode, SetLastError = true)] | |
//private extern static System.IntPtr WinHttpConnect(IntPtr hSession, string pswzServerName, ushort nServerPort, uint dwReserved); | |
//[DllImport("winhttp", CharSet = CharSet.Unicode, SetLastError = true)] | |
//private extern static bool WinHttpCrackUrl(string pwszUrl, int dwUrlLength, uint dwFlags, ref URL_COMPONENTS lpUrlComponents); | |
//[DllImport("winhttp", CharSet = CharSet.Unicode, SetLastError = true)] | |
//private extern static System.IntPtr WinHttpOpenRequest | |
//(IntPtr hConnect, string pwszVerb, IntPtr pwszObjectName, string pwszVersion, string pwszReferrer, IntPtr ppwszAcceptTypes, uint dwFlags); | |
[DllImport("winhttp", SetLastError = true)] | |
private extern static bool WinHttpSetOption(IntPtr hInternet, uint dwOption, ref WINHTTP_PROXY_INFO lpBuffer, int dwBufferLength); | |
//[DllImport("winhttp", CharSet = CharSet.Unicode, SetLastError = true)] | |
//private extern static bool WinHttpSendRequest(IntPtr hRequest, string pwszHeaders, uint dwHeadersLength, IntPtr lpOptional, uint dwOptionalLength, uint dwTotalLength, ref uint dwContext); | |
//[DllImport("winhttp", SetLastError = true)] | |
//private extern static bool WinHttpReceiveResponse(IntPtr hRequest, IntPtr lpReserved); | |
//[DllImport("winhttp", SetLastError = true)] | |
//private extern static bool WinHttpQueryDataAvailable(IntPtr hRequest, ref uint lpdwNumberOfBytesAvailable); | |
//[DllImport("winhttp", SetLastError = true)] | |
//unsafe private extern static bool WinHttpReadData(IntPtr hRequest, void* lpBuffer, uint dwNumberOfBytesToRead, ref uint lpdwNumberOfBytesRead); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment