问题
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?
回答1:
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 int
s (~2GB). As long as Encoding.GetBytes
can handle it and you have sufficient RAM you are unlikely to be limited before that.
来源:https://stackoverflow.com/questions/46446081/maximum-data-length-for-webclient-uploadstring-method