How to read HTTP response headers from web service response?

大城市里の小女人 提交于 2019-12-23 23:06:27

问题


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.



来源:https://stackoverflow.com/questions/1815650/how-to-read-http-response-headers-from-web-service-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!