Web Request through Proxy using RestSharp

后端 未结 4 648
谎友^
谎友^ 2020-12-14 19:43

I\'m trying to make a webrequest through a proxy on Windows phone 7. From what I can see the Compact Framework does not include the configuring of a proxy for the HttpWebReq

4条回答
  •  难免孤独
    2020-12-14 19:52

    Some example using a method and a class: The call:

                var client = new RestClient(urlbase);
                if(myConfigInstance.ProxyActive) {
                     client.Proxy = GetWebProxy(myConfigInstance);
                }
    

    and the method:

      public static WebProxy GetWebProxy(ProxySettings proxySettings)
        {
            WebProxy proxy;
            try
            {
                proxy = new WebProxy(proxySettings.Server, Int32.Parse(proxySettings.Port))
                {
                    Credentials = new NetworkCredential(proxySettings.Username, proxySettings.Password, proxySettings.Domain)
                };
            }
            catch (Exception ex)
            {
              throw new Exception("Error");
            }
            return proxy;
        }
    

    and the class:

    public class ProxySettings
    {
        public bool ProxyActive { get; set; }
        public string Port { get; set; }
        public string Server { get; set; }
        public string Username { get; set; }
        public string Password { get; set; }
        public string Domain { get; set; }
    }
    

提交回复
热议问题