Home » , » Help in .net code-“System.Net.HttpWebRequest

Help in .net code-“System.Net.HttpWebRequest

Written By M.L on புதன், 21 செப்டம்பர், 2011 | செப்டம்பர் 21, 2011

Can anyone please send me code to use “System.Net.HttpWebRequest” with post method and I need to pass some parameters to webpage.As the url is exceding more than 350 characters I have to use post method.

Answer:

This code may help
 
string strNewValue;
string strResponse;
 
HttpWebRequest req = (HttpWebRequest) WebRequest.Create("http://domain.com/page.aspx");
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
 
//Parameters
strNewValue = strFormValues + "&param1=value1&parm2=value2";
req.ContentLength = strNewValue.Length;
 
//Request
StreamWriter stOut = new StreamWriter (req.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(strNewValue);
stOut.Close();
 
//Response
StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
strResponse = stIn.ReadToEnd();
stIn.Close();
 
please provide your comments:

0 comments:

கருத்துரையிடுக

Popular Posts

General Category