0
如何獲取NameValueCollection值POST的Content-Length?C#在NameValueCollection中發佈值
我正在添加「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;
}
'UploadValues'應該爲你做的該屬性。 – SLaks
根據http://msdn.microsoft.com/en-us/library/system.net.webclient.headers.aspx,您不能使用「WebClient」設置「Content-Length」標頭。 –