[英]How do I get an HttpWebResponse for “200 OK”?
I know how to capture the HTTP response (in the form of an HttpWebResponse
) in case of an error , but how do I do this when the method returns 200 OK? 我知道如何在出现错误的情况下捕获HTTP响应(以HttpWebResponse
的形式),但是当方法返回200 OK时如何执行此操作? I'd like to handle all the responses uniformly. 我想统一处理所有的回复。
// IService.cs
public async Task Ping();
// Client.cs
public static void ReactToHttpResponse(HttpWebResponse res)
{
// Play with the http response ...
}
await service.Ping(); // => 200 OK, on the wire
ReactToHttpResponse(/* ??? */) // How to capture the HttpWebResponse?
Or should I be capturing a different response class? 或者我应该捕获不同的响应类?
Does the status code property help? 状态代码属性有帮助吗?
http://msdn.microsoft.com/en-us/library/system.net.httpwebresponse.statuscode.aspx http://msdn.microsoft.com/en-us/library/system.net.httpwebresponse.statuscode.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.