WebBrowser Proxy C # code implementation

Source: Internet
Author: User

Microsoft WebBrowser control is IE plug-in, all of his functions are like IE, of course, the same settings, the following WebBrowser how to set up the agent, do not use this against the Advertising alliance OH

You can change the proxy with InternetSetOption method from the Wininet.dll, here are a example to set the proxy:

Using System.Runtime.InteropServices;

public struct Struct_internet_proxy_info
{
public int dwaccesstype;
public INTPTR proxy;
Public IntPtr Proxybypass;
};
[DllImport ("Wininet.dll", SetLastError = True)]
private static extern bool InternetSetOption (IntPtr hinternet, int dwoption, IntPtr lpbuffer, int lpdwbufferlength);
private void Refreshiesettings (string strproxy)
{
const int internet_option_proxy = 38;
const int internet_open_type_proxy = 3;
Struct_internet_proxy_info Struct_ipi;
Filling in structure
Struct_ipi.dwaccesstype = Internet_open_type_proxy;
Struct_ipi.proxy = Marshal.stringtohglobalansi (strproxy);
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 Ireturn = InternetSetOption (IntPtr.Zero, Internet_option_proxy, Intptrstruct, marshal.sizeof (Struct_IPI));
}
private void SomeFunc ()
{
Refreshiesettings ("192.168.1.200:1010");
System.Object nullobject = 0;
String strtemp = String.Empty;
System.Object nullobjstr = strtemp;
Axwebbrowser1.navigate ("http://willstay.tripod.com", ref nullobject, ref NULLOBJSTR, ref NULLOBJSTR, ref NULLOBJSTR);
}

--------------------------------------------------------------------------------------------------------------- ----------------------

Yesterday, the voting opportunity to a new problem, yesterday began the poll began now IP address, each address can only cast 5 votes/day. If every time you change the connection of IE as a proxy server, that also trouble dead, if you use WebClient, that yesterday's 2 hours in vain, the internet a wild collect still really found a way, this good run, built a proxy.txt document, inside put on the proxy server received from the Internet, Then the program read into a ListBox, each time you need to change the IP, just click once, you can also re-vote an address.
Attached Proxy.cs

Using system.runtime.interopservices;//needs to add this reference
public struct Struct_internet_proxy_info
{
public int dwaccesstype;
public INTPTR proxy;
Public IntPtr Proxybypass;
};
[DllImport ("Wininet.dll", SetLastError = True)]
private static extern bool InternetSetOption (IntPtr hinternet, int dwoption, IntPtr lpbuffer, int lpdwbufferlength);
public void Refreshiesettings (string strproxy)
{
const int internet_option_proxy = 38;
const int internet_open_type_proxy = 3;
Struct_internet_proxy_info Struct_ipi;
Filling in structure
Struct_ipi.dwaccesstype = Internet_open_type_proxy;
Struct_ipi.proxy = Marshal.stringtohglobalansi (strproxy);
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 Ireturn = InternetSetOption (IntPtr.Zero, Internet_option_proxy, Intptrstruct, marshal.sizeof (Struct_IPI));
}

When used, call Refreshiesettings
py.proxy py1 = new proxy(); 
py1.RefreshIESettings(”221.4.155.51:3128″); 

webBrowser1.Navigate(”http://www.hfxsy.cn”, null, null, null);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.