0

How do I get the Content-Length for a POST of NameValueCollection values?

I am adding the "Content-Length" header, but don't know what to put in it.

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;
}
Yuck
  • 49,664
  • 13
  • 105
  • 135
Ian Vink
  • 66,960
  • 104
  • 341
  • 555

1 Answers1

0

You can not set that property on a WebClient

Ian Vink
  • 66,960
  • 104
  • 341
  • 555