This may not be Twitter specific, but I am calling an API and when my params pushes over a certain size limit, the request fails with either a webException (sendFailure or receiveFailure).
I've pinpointed the max length of the parameters part as being between 12251 and 12269 characters long. Below 12251, it always works fine - above 12269 it fails!
In all machine.config files on the machine, I have this:
<httpRuntime maxRequestLength="32768"/>
My oAuth implementation is absolutely fine as well - as below this length, the parameters part works fine.
For info, here is the C# part (but this is not needed because as I've said, the code works it's just when this request length hits a ceiling):
private void InitialiseWebStreamRequest()
{
var userAgent = <<userAgent>>;
var requestBuilder = new Twitterizer2.WebRequestBuilder(new Uri("https://stream.twitter.com/1.1/statuses/filter.json"), Twitterizer2.HTTPVerb.POST, <<tokens>>, userAgent);
var parameters = string.Join(",", arrayOfNumbers);
requestBuilder.Parameters.Add("follow", parameters);
WebRequest = requestBuilder.PrepareRequest();
WebRequest.ContentType = "application/x-www-form-urlencoded";
WebRequest.Timeout = 120000;
}
The web "PrepareRequest" part is straight from the open source Twitterizer2 library and this prepares a request with oAuth as follows:
public HttpWebRequest PrepareRequest()
{
SetupOAuth();
formData = null;
string contentType = string.Empty;
if (!Multipart)
{ //We don't add the parameters to the query if we are multipart-ing
AddQueryStringParametersToUri();
}
else
{
string dataBoundary = "--------------------r4nd0m";
contentType = "multipart/form-data; boundary=" + dataBoundary;
formData = GetMultipartFormData(Parameters, dataBoundary);
this.Verb = HTTPVerb.POST;
}
HttpWebRequest request;
request = (HttpWebRequest)WebRequest.Create(this.RequestUri);
if (this.UseCompression == true)
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
else
request.AutomaticDecompression = DecompressionMethods.None;
if (this.Proxy != null)
request.Proxy = Proxy;
if (!this.UseOAuth && this.networkCredentials != null)
{
request.Credentials = this.networkCredentials;
request.UseDefaultCredentials = false;
}
else
{
request.UseDefaultCredentials = true;
}
request.Method = this.Verb.ToString();
request.ContentLength = Multipart ? ((formData != null) ? formData.Length: 0) : 0;
if (this.UseOAuth)
{
request.Headers["Authorization"] = GenerateAuthorizationHeader();
}
if (Multipart)
{ //Parameters are not added to the query string, post them in the request body instead
request.ContentType = contentType;
IAsyncResult getRequestStreamResult = request.BeginGetRequestStream(
res =>
{
}, null);
using (Stream requestStream = request.EndGetRequestStream(getRequestStreamResult))
{
if (formData != null)
{
requestStream.Write(formData, 0, formData.Length);
}
}
}
return request;
}
Anyone have any ideas?