How can I read the HTTP response headers from a web service response in C#?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
After digging through MSDN, all I needed to do was to override the GetWebResponse
method, and then I could access the response headers:
public class MyWSProxy : HttpWebClientProtocol
{
protected override WebResponse GetWebResponse(WebRequest request)
{
System.Net.WebResponse wr = base.GetWebResponse(request);
// read a response header
object val = wr.Headers["key"];
return wr;
}
}
回答2:
If you're getting back an HttpResponse
, you can just query the HttpResponse.Headers
property.
回答3:
Can't you just refer to HttpContext.Current.Response.Headers
in your webservice?
I'm not sure if that'll work.