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:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...