如何使用 .NET HttpWebRequest API 从响应中读取 HTTP 标头? [英] How to read HTTP header from response using .NET HttpWebRequest API?
问题描述
我的应用目前使用 OAuth 与 Twitter API 通信.早在 12 月,Twitter 就将 OAuth 的速率限制提高到每小时 350 个请求.但是,我没有看到这一点.我仍然从
(来源:yfrog.com) >
知道我做错了什么吗?
查看原始响应文本(例如,使用 Fiddler).如果标题不存在,则没有多少 C# 代码会使其出现.:) 从您所展示的内容来看,响应中似乎没有标题.
更新:当我去:http://twitter.com/account/rate_limit_status.xml 没有 X-RateLimit-Limit
标头.但是当我访问 http://twitter.com/statuses/public_timeline.xml 时,它是那里.所以我认为你只需要使用不同的方法.
它仍然显示 150,不过!
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.
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();
}
}
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.
(source: yfrog.com)
Any idea what I am doing wrong?
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.
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.
It still says 150, though!
这篇关于如何使用 .NET HttpWebRequest API 从响应中读取 HTTP 标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!