WinRT的HttpBaseProtocolFilter类

HttpClient类实例化的时候内部会创建一个HttpBaseProtocolFilter的对象,用于建立TCP连接,接收返回字节,管理缓存,cookie,证书等:

public sealed class HttpBaseProtocolFilter : IHttpFilter, IDisposable {
public HttpBaseProtocolFilter();
// Gets an object allowing you to set cache read and write behavior
public HttpCacheControl CacheControl { get; }
// Returns the cookie manager allowing you to get and set cookies
public HttpCookieManager CookieManager { get; }
// Allows you to set the maximum connections from filter to an HTP server
public UInt32 MaxConnectionsPerServer { get; set; }
// Can filter follow a redirect response (default = true)
public Boolean AllowAutoRedirect { get; set; }
// Can filter automatically decompress response data (default = true)
public Boolean AutomaticDecompression { get; set; }
// Ignorable SSL errors
public IList<ChainValidationResult> IgnorableServerCertificateErrors { get; }
// Can filter use a proxy to send request
public Boolean UseProxy { get; set; }
// Sets HTP proxy credentials
public PasswordCredential ProxyCredential { get; set; }
// Sets client certificate to send to server (if requested)
public Certificate ClientCertificate { get; set; }
// Sets HTP server credentials
public PasswordCredential ServerCredential { get; set; }
// Can filter prompt for user credentials at server's request (default = true)
public Boolean AllowUI { get; set; }
// Sends HTP request over the wire (SendRequestAsync is IHttpFilter's only member)
public IAsyncOperationWithProgress<HttpResponseMessage, HttpProgress>
SendRequestAsync(HttpRequestMessage request);
// Releases unmanaged resources associated with the HttpBaseProtocolFilter
public void Dispose();
}

检查返回的cookie:

using (HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter())
using (HttpClient client = new HttpClient(filter)) {
HttpRequestMessage request =
new HttpRequestMessage(HttpMethod.Get, new Uri("http://Bing.com/"));
HttpResponseMessage response = await client.SendRequestAsync(request);
// See the returned cookies (HttpCookieManager also has SetCookie and DeleteCookie methods)
foreach (HttpCookie cookie in filter.CookieManager.GetCookies(request.RequestUri)) {
String cookieInfo = String.Format(
"Domain={0}, Expires={1}, HttpOnly={2}, Name={3}, Path={4}, Secure={5}, Value={6}",
cookie.Domain, cookie.Expires, cookie.HttpOnly, cookie.Name, cookie.Path,
cookie.Secure, cookie.Value);
}
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值