.net – Built-in methods to construct a POST request body in .NET

httpnetpost

I am looking for a built-in utility method in .NET for constructing HTTP POST message body for the two common content types:

  • application/x-www-form-urlencoded
  • multipart/form-data

I'd rather use someone else's ready and tested implementation than roll my own, even though I realise it's not difficult to do so. However there doesn't seem to be anything in System.Web to this effect.

Any suggestions?

(No need to explain how to construct the POST message body manually… that's not what this question is about)

Best Answer

Even easier, I like WebClient.UploadValues method. Just give it a NameValueCollection and it handles the rest:

http://msdn.microsoft.com/en-us/library/system.net.webclient.uploadvalues.aspx