How to read HTTP response headers from web service

2019-07-18 13:59发布

How can I read the HTTP response headers from a web service response in C#?

3条回答
对你真心纯属浪费
2楼-- · 2019-07-18 14:23

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;
    }
}
查看更多
Deceive 欺骗
3楼-- · 2019-07-18 14:27

Can't you just refer to HttpContext.Current.Response.Headers in your webservice?
I'm not sure if that'll work.

查看更多
Rolldiameter
4楼-- · 2019-07-18 14:33

If you're getting back an HttpResponse, you can just query the HttpResponse.Headers property.

查看更多
登录 后发表回答