Maximum data length for WebClient.UploadString method

微笑、不失礼 提交于 2021-02-10 06:14:25

问题


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 ints (~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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!