Advertisement
Guest User

Untitled

a guest
Mar 12th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. var credentialStringValue = "proxyUser:proxyPassword";
  2. byte[] credentialByteArray = ASCIIEncoding.ASCII.GetBytes(credentialStringValue);
  3. var credentialBase64String = Convert.ToBase64String(credentialByteArray);
  4.  
  5. string Headers = string.Format("Proxy-Authorization: Basic {0}{1}", credentialBase64String, Environment.NewLine);
  6.  
  7. ws.Navigate(url,TargetFrameName,PostData,Headers);
  8.  
  9. // do what you want with proxy class
  10. WebProxy webProxy = new WebProxy(host, port)
  11. {
  12. Credentials = ...
  13. }
  14.  
  15. HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://example.com");
  16. webRequest.Proxy = webProxy;
  17.  
  18. HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
  19. Stream receiveStream = response.GetResponseStream();
  20.  
  21. WebBrowser webBrowser = new WebBrowser();
  22. webBrowser.DocumentStream = receiveStream;
  23.  
  24. Registry.SetValue(keyName, "ProxyServer", proxyhost, RegistryValueKind.String);
  25. Registry.SetValue(keyName, "ProxyEnable", proxyEnabled ? "1" : "0", RegistryValueKind.DWord);
  26.  
  27. Registry.SetValue(keyName, "ProxyPass", password, RegistryValueKind.String);
  28. Registry.SetValue(keyName, "ProxyUser", username, RegistryValueKind.String);
  29.  
  30. //<-loopback>;<local>
  31. Registry.SetValue(keyName, "ProxyOverride", "*.local", RegistryValueKind.String);
  32.  
  33.  
  34. // These lines implement the Interface in the beginning of program
  35. // They cause the OS to refresh the settings, causing IP to realy update
  36. InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0);
  37. InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);
  38. }
  39.  
  40. Credential credentials= new Credential
  41. {
  42. Username = $"Usernmae",
  43. Password = "Password",
  44. Target = "Target (usualy proxy domain}",
  45. Type = CredentialType.Generic,
  46. PersistanceType = PersistanceType.Enterprise
  47. };
  48. credentials.Save();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement