Web developers wiki ASP.NET Sitecore Sharepoint Kentico by Evident Interactive

Use POST method in HttpWebRequest

Modified: 2009/11/20 17:28 by jim - Categorized as: ASP.NET, Csharp, Visual Studio
         string param = "somevalue";
         string otherParam = "othervalue";

         ASCIIEncoding encoding = new ASCIIEncoding();
	string postData = "param=" + param;
	postData += ("&notherparam=" + otherParam);
	byte[] data = encoding.GetBytes(postData);
		
	HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create("http://recievepostparams.aspx");
	hwr.Method = "POST";
	hwr.ContentType = "application/x-www-form-urlencoded";
	hwr.ContentLength = data.Length;
			
	Stream newStream = hwr.GetRequestStream();
	// Send the data.
	newStream.Write(data, 0, data.Length);
	newStream.Close();

 © Evident Interactive BV