How to post data using Httpwebrequest class in asp.net - How to post data from one website to another site using HttpWebRequest class ....
You need to import the following namespaces
C#
using System.Text;
using System.Net;
using System.IO;
Sample code refer
protected void SendrequestToBookroom()
{
string URI = "your url ";
System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
//Add these, as we're doing a POST
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
//We need to count how many bytes we're sending.
//Post'ed Forms should be name=value&
byte[] bytes = System.Text.Encoding.ASCII.GetBytes("minorRev=26&cid=55505");
req.ContentLength = bytes.Length;
using (Stream os = req.GetRequestStream())
{
os.Write(bytes, 0, bytes.Length); //Push it out there
os.Close();
}
WebResponse resp = req.GetResponse();
if (resp == null)
Response.Write("null");
StreamReader sr = new StreamReader(resp.GetResponseStream());
Response.Write(sr.ReadToEnd().Trim());
resp.Close();
sr.Close();
}
Source from :
Fetching the Posted Data
http://aspsnippets.com/Articles/Post-data-to-another-site-in-ASP.Net.aspx
http://msdn.microsoft.com/en-us/library/debx8sh9%28v=vs.110%29.aspx
Comments
Post a Comment