簡體   English   中英

C#從NameValueCollection中發布值

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM