Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 21st, 2012  |  syntax: None  |  size: 0.53 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. C# POSTing values from NameValueCollection
  2. public static string Post (string url, NameValueCollection formData)
  3. {
  4.     string response;
  5.     int length = formData.???
  6.  
  7.     using (WebClient webClient = new WebClient())
  8.     {
  9.         webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
  10.         webClient.Headers.Add ("Content-Length", length);
  11.         byte[] responseBytes = webClient.UploadValues (url, "POST", formData);
  12.         response = Encoding.UTF8.GetString (responseBytes);
  13.     }
  14.  
  15.     return response;
  16. }