2

I have the following code in my asp.net mvc app -

string URI = "http://send.url.com/smsapi/sender.php";     
string queryParameters= "a long query string";

string xmlResult = "";
using (WebClient wc = new WebClient())
{
    wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
    xmlResult = wc.UploadString(URI, queryParameters);
}

My question is how long queryParameters can be for WebClient.UploadString method?

s.k.paul
  • 7,099
  • 28
  • 93
  • 168
  • 1
    Have you checked [c# webClient Upload String cuts off](https://stackoverflow.com/questions/26778191/c-sharp-webclient-upload-string-cuts-off) – rmjoia Sep 27 '17 at 10:57
  • 1
    If its not documented then its reasonable to assume there isn't one. Any issue your facing is likely encoding or server side related. – Alex K. Sep 27 '17 at 10:59

1 Answers1

2

The WebClient class enforces no limit on the length of a string. As far as it is concerned it is transmitting bytes of data.

Reference Source if you want to check yourself

And the method it calls

The only theoretical limit is Int32.MaxValue bytes because of the internal conversion/encoding methods working with ints (~2GB). As long as Encoding.GetBytes can handle it and you have sufficient RAM you are unlikely to be limited before that.

Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62