1
Reply

Send http request and get result

jitendra chaudhary

jitendra chaudhary

Feb 7 2017 2:44 AM
222
Hello Sir,
 
 
I am using below code for send request .
Send request is working fine but not return result on sending request page .
 
Please help me ASAP.
protected void Button1_Click(object sender, EventArgs e)
{
string remoteUrl = "http://localhost:8917/testweb/use_lodar.aspx";
string firstName = "[email protected]";
string lastName = "65432177";

ASCIIEncoding encoding = new ASCIIEncoding();
string data = string.Format("FirstName={0}&LastName={1}", firstName, lastName);
byte[] bytes = encoding.GetBytes(data);
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(remoteUrl);
httpRequest.Method = "POST";
httpRequest.ContentType = "application/x-www-form-urlencoded";
httpRequest.ContentLength = bytes.Length;
using (Stream stream = httpRequest.GetRequestStream())
{
stream.Write(bytes, 0, bytes.Length);
stream.Close();
}

HttpWebResponse response = (HttpWebResponse)httpRequest.GetResponse();
StreamReader streamReader = new StreamReader(response.GetResponseStream());
string responseData = streamReader.ReadToEnd();
streamReader.Close();


}

Thanks
jitendra chaudhary.

Answers (1)