I wanna make a post form in code behind. I have simple html post is working but when I try make it WebRequest I can\'t make it work.
Thanks for you time in advance.<
Try like this.
using (WebClient client = new WebClient())
{
byte[] response = client.UploadValues("http://dork.com/service", new NameValueCollection()
{
{ "home", "Cosby" },
{ "favorite+flavor", "flies" }
});
}
You will need these includes:
using System;
using System.Collections.Specialized;
using System.Net;
If you're insistent on using a static method/class:
public static class Http
{
public static byte[] Post(string uri, NameValueCollection pairs)
{
byte[] response = null;
using (WebClient client = new WebClient())
{
response = client.UploadValues(uri, pairs);
}
return response;
}
}
Then simply:
Http.Post("http://dork.com/service", new NameValueCollection() {
{ "home", "Cosby" },
{ "favorite+flavor", "flies" }
});