如何使用.NET HttpWebRequest的API来读取响应HTTP头? [英] How to read HTTP header from response using .NET HttpWebRequest API?

查看:826
本文介绍了如何使用.NET HttpWebRequest的API来读取响应HTTP头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序目前使用OAuth与Twitter的API进行通信。在12月,Twitter的调升速率限制的OAuth每小时350请求。不过,我没有看到这一点。我仍然href=\"http://apiwiki.twitter.com/Twitter-REST-API-Method%3a-account%C2%A0rate_limit_status\">占到/ rate_limit_status 方法

My app currently uses OAuth to communicate with the Twitter API. Back in December, Twitter upped the rate limit for OAuth to 350 requests per hour. However, I am not seeing this. I am still getting 150 from the account/rate_limit_status method.

有人告诉我,我需要使用 X-RateLimit限额 HTTP头,以获得新的限速。然而,在我的代码,我没有看到这个头。

I was told that I needed to use the X-RateLimit-Limit HTTP header to get the new rate limit. However, in my code, I do not see that header.

下面是我的代码...

Here is my code...

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(newURL);
request.Method = "GET";
request.ServicePoint.Expect100Continue = false;
request.ContentType = "application/x-www-form-urlencoded";

using (WebResponse response = request.GetResponse())
{
    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
    {
        responseString = reader.ReadToEnd();
    }
}

如果我检查响应,我可以看到它有标题属性,并有16头。不过,我没有 X-RateLimit限额列表

If I inspect the response, I can see that it has a property for Headers, and that there are 16 headers. However, I do not have X-RateLimit-Limit in the list.

任何想法,我做错了?

推荐答案

看原始响应文本(例如,使用Fiddler)。如果标题是不存在的,没有任何的C#代码量会使其出现。 :)从你已经证明什么,似乎头是不是在回应

Look at the raw response text (e.g., with Fiddler). If the header isn't there, no amount of C# code is going to make it appear. :) From what you've shown, it seems the header isn't in the response.

更新:当我去:的 http://twitter.com/account/rate_limit_status.xml 没有 X-RateLimit限额头。但是,当我去 http://twitter.com/statuses/public_timeline.xml ,它的存​​在。因此,我认为你只需要使用不同的方法。

Update: When I go to: http://twitter.com/account/rate_limit_status.xml there is no X-RateLimit-Limit header. But when I go to http://twitter.com/statuses/public_timeline.xml, it's there. So I think you just need to use a different method.

它仍然说150,但!

这篇关于如何使用.NET HttpWebRequest的API来读取响应HTTP头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆