HTTPWebRequest - POST Method.

Sample for HTTPWebRequest using POST Method.

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("url")

request.Method = "POST";

string parameter = "";

parameter += "test=test1&";
parameter += "testing=testing1&";
parameter += "demo=demo1";

byte[] byteArray = Encoding.UTF8.GetBytes(parameter);

request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

if (HttpStatusCode.OK == response.StatusCode)
{
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
responseFromServer = reader.ReadToEnd();
File.WriteAllText(filepath, responseFromServer);
response.Close();
}