Hi,
I want to post two arguments to my aspx file and after take html response from this
Please help me
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Francis SusaimichaelPosted Feb 1, 2015, 7:18 AM
WebRequest request = WebRequest.Create("YourURLHere");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "YourArgumentsToBePost";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
// Get the response.
WebResponse response = request.GetResponse();
// Display the status.
dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader readerst = new StreamReader(dataStream);
// Read the content.
string responseFromServer = readerst.ReadToEnd();
readerst.Close();
// reader.Close();
dataStream.Close();
response.Close();