设置特定于服务请求HTTP客户端+ REST的代理服务器

时间:2012-11-20 05:23:58

标签: c# wcf wcf-rest

using (var client = new System.Net.Http.HttpClient())
            {
                var response = client.GetAsync(fullUrl).Result;
}

我正在创建如上所述的HTTP客户端以使用RESTfull服务。 我应该能够为此服务请求设置代理。 如何仅设置特定于此服务请求的代理服务器?

2 个答案:

答案 0 :(得分:1)

System.Net.Http.HttpClient没有TransportSettings属性,关于Microsoft.Http程序集是未知的。

答案 1 :(得分:-1)

使用Microsoft.Http我可以

 HttpClient client = new HttpClient();
                /*Set Credentials to authenticate proxy*/
                client.TransportSettings.Proxy = new WebProxy(proxyAddress);
                client.TransportSettings.Proxy.Credentials = CredentialCache.DefaultCredentials;
                client.TransportSettings.Credentials = CredentialCache.DefaultCredentials;

                client.BaseAddress = new Uri(this.baseUrl);
                var response = client.Get(fullUrl);

                var jsonResponce = response.Content.ReadAsJsonDataContract<mYResponseoBJECT>();


 public static T ReadAsJsonDataContract<T>(this  HttpContent content)
        {
            return (T)content.ReadAsJsonDataContract<T>(new DataContractJsonSerializer(typeof(T)));
        }