Posted By

wraith808 on 06/29/09


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

paelgr
umang_nine


Example Web Proxy Use


 / Published in: C#
 

  1. var result = new StringBuilder();
  2. try
  3. {
  4. var transferProxy = new WebProxy("<webproxy>:<proxyport>/", true);
  5. transferProxy.Credentials = new NetworkCredential("<username>", "<password>", "<domain>");
  6. var transferRequest = WebRequest.Create("http://www.snipplr.com");
  7. transferRequest.Proxy = transferProxy;
  8. HttpWebResponse transferResponse = (HttpWebResponse)transferRequest.GetResponse();
  9. System.IO.Stream outputStream = transferResponse.GetResponseStream();
  10. System.Text.Encoding outputEncoding = System.Text.Encoding.GetEncoding("utf-8");
  11. System.IO.StreamReader outputReader = new System.IO.StreamReader(outputStream, outputEncoding);
  12. char[] chars = new Char[256];
  13. int readCount = outputReader.Read(chars, 0, 256);
  14. int totalRead = readCount;
  15. while(readCount > 0)
  16. {
  17. string str = new String(chars, 0, 256);
  18. result.Append(str);
  19. readCount = outputReader.Read(chars, 0, 256);
  20. }
  21. transferResponse.Close();
  22. outputStream.Close();
  23. outputReader.Close();
  24. }
  25. catch(Exception ex)
  26. {
  27. string str = ex.Message;
  28. }
  29. StreamWriter fileOut = new StreamWriter("testProxy.txt");
  30. fileOut.WriteLine(result.ToString());
  31. fileOut.Close();
  32.  

Report this snippet  

You need to login to post a comment.