[英]C# POSTing values from NameValueCollection
如何獲得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;
}
您不能在WebClient上設置該屬性
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.