RequestUtils.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Net;
  5. namespace FastReport.Cloud
  6. {
  7. /// <summary>
  8. /// Provides utils for the web request.
  9. /// </summary>
  10. public static class RequestUtils
  11. {
  12. #region Public Methods
  13. /// <summary>
  14. /// Sets proxy settings for web request.
  15. /// </summary>
  16. /// <param name="request">The web request.</param>
  17. /// <param name="settings">The cloud proxy settings.</param>
  18. public static void SetProxySettings(WebRequest request, CloudProxySettings settings)
  19. {
  20. if (settings != null)
  21. {
  22. StringBuilder proxyAddress = new StringBuilder(settings.Server);
  23. if (settings.Port != 0)
  24. {
  25. proxyAddress.AppendFormat(":{0}", settings.Port.ToString());
  26. }
  27. request.Proxy = new WebProxy(proxyAddress.ToString());
  28. if (!String.IsNullOrEmpty(settings.Username))
  29. {
  30. request.Proxy.Credentials = new NetworkCredential(settings.Username, settings.Password);
  31. }
  32. }
  33. }
  34. #endregion // Public Methods
  35. }
  36. }