C# C从NameValueCollection过帐值
如何获取NameValueCollection值帖子的内容长度 我正在添加内容长度标题,但不知道该放什么C# C从NameValueCollection过帐值,c#,post,webclient,webclient.uploaddata,C#,Post,Webclient,Webclient.uploaddata,如何获取NameValueCollection值帖子的内容长度 我正在添加内容长度标题,但不知道该放什么 public static string Post (string url, NameValueCollection formData) { string response; int length = formData.??? using (WebClient webClient = new WebClient()) { webClient.
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;
}
您不能在WebClient上设置该属性。UploadValues应为您设置该属性。根据,您不能使用WebClient设置内容长度标题。