Bandwidth Limits & HttpWebRequest - c#

Is there any way to throttle a HttpWebRequest? I can call GetResponse() but that will download the response at it's own speed and I may want to limit the rate of download.
So far I can't see anything that would let me?

As Thomas Levesque said, GetResponse() downloads the headers and the beginning and not the whole item like previously thought.
This means that I can read in chunks and throttle as needed.

Could you use the Range Http header, if the server supports Range headers, to tell the server to only send back part of the response?

Related

Can stackify prefix capture full response body?

I have .net core project and add stackify prefix to monitor requests, but in response prefix show only headers but not body of response. It is possible to see all response body?
On prefix site I found information:
It can capture incoming post data, it can also capture the response and the response headers and part of the response body. Right now, we limit that to only be a certain amount of characters so if it’s returning something larger, it won’t capture all of it.
It is possible to change this?
There is not a way to change this at the moment if the response body is too large it will not show up in the traces.
Stackify has an Ideas portal that you can make suggested changes to, their COO gets notified when a new request has been made and when a request has been up voted by several clients. He takes each request into good consideration and arranges them into Stackify's road map. Also you can subscribe to the ideas to keep updated on its progress.
https://ideas.stackify.com

Error 403 with Twitters streaming API while sending a POST request - C#

I'm building an bot that auto replies to tweets that contain specific words. I am using HttpWebRequest to make a request to the streaming API and posting the tweet. Only problem is that the twitter API limits the ammount of requests you can make in a specific ammount of time. This makes the stream request successful but the request to post a tweet fails with the 403 error. How can i avoid this? (Not really sure if this is actually the problem, but it seems so.)
I used this as an layout on how the stream request thingy works http://www.emoticode.net/c-sharp/twitter-stream-api-client-example.html
If you know anything about this, let me know.
According to the Twitter docs(error codes, limits) you should get an error message explaining what limit you hit (if you hit it). That should clarify if that is truly your problem.
If it is I suggest using a message queue or a response schedule, to allow you to track how many tweets you are sending. Maybe you could also assign priorities to those tweets you want to respond to, even filter out some low priority ones eventually. That depends really on the load of tweets you will be processing.

Best practise - C# .Net console app POST to a url

What would be the best approach to make a POST request to a web service url, in a Console App?
I tried using WebClient.uploadstring but it fails whenever the POSTed data is slightly bigger.
I tried HTTPClient but it's an async call.. so I had to additionally use ManualResetEvent to keep it alive till the server response is received..
I'd like to know what's the best way to do this. Please let me know if mpre info is required.
What do you mean by "huge"?
If you are posting large amounts of data to the URL, then you could be exceeding the maximum request size, in which case no method of requesting the URL with that amount of post data will work.
I ended up using HTTPClient's PostAsync(url, content).Result which waits till it gets a response! neat stuff..

REST Streaming in Windows Phone App C#

I've been using REST calls with my app to get and post data. I want to implement REST streaming now though so that I can immediately get any changes to the data.
I have no clue how to implement REST streaming though. How do I go about setting connection in my app. Also, do you know have any tips or best practices when using REST streaming in an app. Any help is appreciated, thanks!
I've never has a chance to try that but here is some clues that might help.
If you want to get a streamed content from your server, you can have a look at HttpClient.GetAsync(Uri, HttpCompletionOption) | getAsync(Uri, HttpCompletionOption). The available options allow you to control how the response is handled. You can for example wait for the response headers and then once available read the response content stream from the HttpResponseMessage.Content property.
You can also have a look at the IHttpFilter interface. It will allow you to "hook up" the HTTP stack and extract the response as it arrives.

Compressing string

I tried send some data(variable 1 - 4 MB) by http headers,but returned the following error in ajax.response:
HTTP Error 400. The size of the request headers is too long.
there something that I can do or the method single is compressing the data? if yes,how I do this?
any help is appreciated. Thanks in advance!
If you're sending around that much data, put it in the body of the request (e.g, in a HTTP POST), not in the headers. Increasing the header size limit (as cwallenpoole suggests) will still cause problems with users who are behind web proxies.
Most http server accept about 8-16KB for the header. Therefore, if your data is too large, just use POST method to send it.
Personally, I would just up the size of the acceptable header. MS suggests the same and gives instructions on how to raise it to 16 MB if necessary (see MaxRequestBytes).

Categories

Resources