0

如何获取 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;
}
4

1 回答 1

0

您不能在 WebClient 上设置该属性

于 2011-11-21T03:43:06.247 回答