Advertisement
User12345678910

Proxy on WebBrowser in C#

Jul 25th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Runtime.InteropServices;
  4.  
  5. namespace Webbrowser_Proxy
  6. {
  7.     public partial class Form1 : Form
  8.     {
  9.         public Form1()
  10.         {
  11.             InitializeComponent();
  12.         }
  13.  
  14.         [DllImport("wininet.dll", SetLastError = true)]
  15.         private static extern bool InternetSetOption(
  16.             IntPtr dwL,
  17.             int dw,
  18.             IntPtr dwB,
  19.             int dwBL
  20.             );
  21.         public struct SIPI
  22.         {
  23.             public int dwAT;
  24.             public IntPtr pro;
  25.             public IntPtr prB;
  26.         }
  27.  
  28.         private void UseProxy(string Proxy)
  29.         {
  30.             const int PO = 38;
  31.             const int POI = 3;
  32.  
  33.             SIPI ISI = default(SIPI);
  34.             ISI.dwAT = POI;
  35.             ISI.pro = Marshal.StringToHGlobalAnsi(Proxy);
  36.             ISI.prB = Marshal.StringToHGlobalAnsi("local");
  37.  
  38.             IntPtr INS = Marshal.AllocCoTaskMem(Marshal.SizeOf(ISI));
  39.  
  40.             Marshal.StructureToPtr(ISI, INS, true);
  41.  
  42.             bool iR = InternetSetOption(IntPtr.Zero, PO, INS, Marshal.SizeOf(ISI));
  43.         }
  44.         private void button1_Click(object sender, EventArgs e)
  45.         {
  46.             webBrowser1.Navigate(textBox1.Text);
  47.         }
  48.  
  49.         private void button2_Click(object sender, EventArgs e)
  50.         {
  51.             UseProxy(textBox3.Text);
  52.             label4.Text = textBox3.Text;
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement