Friday, June 04, 2010

How to post values to diffent page using HttpWebRequest : Asp.net

Using Asp.net HttpWebRequest object we can post data to external page and get a HttpWebResponse

string strId = "regid789654";
string strName = "Charith";
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "userid=" + strId;
postData += ("&username=" + strName);
byte[] data = encoding.GetBytes(postData);
HttpWebRequest request =
    (HttpWebRequest)WebRequest.Create("http://www.domain.com/cart.asp");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
Stream newStream = request.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
 
StreamReader sr = new StreamReader(request.GetResponse().GetResponseStream());
string result = sr.ReadToEnd();
sr.Close();

No comments:

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...