How to read HTTP header from response using .NET HttpWebRequest API?

You should simple be able to use:

using (WebResponse response = request.GetResponse())
{
  string limit = response.Headers["X-RateLimit-Limit"];
  ...
}

If that doesn't work as expected, you can do a watch on response.Headers and see what's in there.


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!