This is my code so far.
/// <summary>
/// An extern method that is used to configure the Internet options for the called
/// web browser instance.
/// </summary>
[DllImport("wininet.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);
[DllImport("wininet.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool InternetSetOption(IntPtr hInternet, int
dwOption, string lpBuffer, int dwBufferLength);
private struct INTERNET_PROXY_INFO
{
public int dwAccessType;
public IntPtr proxy;
public IntPtr proxyBypass;
};
/// <summary>
/// Sets the proxy server for this instance of the WebBrowser control using the
/// extern method InternetSetOption (part of wininet.dll).
/// </summary>
/// <param name="proxyServerAddress">The proxy server and port.</param>
public bool SetProxyServer(string proxyServerAddress,string Username,string Password)
{
try
{
const int INTERNET_OPTION_PROXY = 38;
const int INTERNET_OPEN_TYPE_PROXY = 3;
const int INTERNET_OPEN_TYPE_DIRECT = 1;
const int INTERNET_OPTION_PROXY_USERNAME = 43;
const int INTERNET_OPTION_PROXY_PASSWORD = 44;
INTERNET_PROXY_INFO struct_IPI;
// Filling in structure
if (proxyServerAddress == "")
{
// Clear any proxy settings and go "direct" to the Internet.
struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_DIRECT;
struct_IPI.proxy = IntPtr.Zero;
struct_IPI.proxyBypass = IntPtr.Zero;
}
else
{
// Assign the specified proxy server and port to access the Internet.
// This supports only anonymous proxy servers; support for authentication
// coming in the future.
struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
struct_IPI.proxy = Marshal.StringToHGlobalAnsi(proxyServerAddress);
struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local");
}
// Allocating memory
IntPtr intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI));
// Converting structure to IntPtr
Marshal.StructureToPtr(struct_IPI, intptrStruct, true);
bool i = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI));
bool user1 = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY_USERNAME, (IntPtr)C, Username.Length + 1);
return i;
I've tried using
bool user1 = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY_USERNAME, (IntPtr)C, Username.Length + 1);to set the username and password but to no avail.
When I try Marshal.GetLastWin32Error() I get 12018.
I need to know how to set the proxy username and password using wininet. I've tried using GlobalSelectionProxy.Select and WebRequest.DefaultWebProxy but neither settings apply to the web browser control which is basically just an internet explorer wrapper.
Any help would be greatly appreciated. I've been stuck on this for hours


Sign In
Create Account

Back to top









