如何获取NameValueCollection值的POST的Content-Length?
我正在添加“Content-Length”标题,但不知道该放入什么内容。
public static string Post (string url, NameValueCollection formData)
{
string response;
int length = formData.???
using (WebClient webClient = new WebClient())
{
webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
webClient.Headers.Add ("Content-Length", length);
byte[] responseBytes = webClient.UploadValues (url, "POST", formData);
response = Encoding.UTF8.GetString (responseBytes);
}
return response;
}
答案 0 :(得分:0)
您无法在WebClient上设置该属性