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

My app currently uses OAuth to communicate with the Twitter API. Back in December, Twitter raised the speed limit for OAuth to 350 requests per hour. However, I do not see this. I still get 150 from the account / rate_limit_status method .

I was told that I need to use the X-RateLimit-Limit HTTP header to get a new speed limit. However, in my code I do not see this 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 check response , I see that it has a property for Headers and that there are 16 headers. However, I do not have an X-RateLimit-Limit in the list.

Image
(source: yfrog.com )

Any ideas what I'm doing wrong?

+9
c # oauth twitter
source share
2 answers

Look at the source of the response (e.g. with Fiddler). If the title does not exist, the amount of C # code will not be displayed. :) From what you showed, it seems that the title is not in the answer.

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 is there. So I think you just need to use a different method.

He still says 150 though!

+2
source

You should just use:

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

If this does not work properly, you can make a clock on response.Headers and see what is there.

+12
source

All Articles