Please refer to the below code. How can I test/debug, whether the below code worked correctly or not. It runs and there are no compilation/runtime errors.
The end result of the below code is to set one of the controls in the page, to hold the POST data from below code. However I haven’t come that far yet.
protected override void OnInit(EventArgs e)
{
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "http://s.com/is/image/scom/2Peel";
byte[] data = encoding.GetBytes(postData);
// Prepare web request...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://m.com/Confirm.aspx?ID=175");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// Send the data.
newStream.Write(data, 0, data.Length);
newStream.Close();
}
Update 1: I tried to find out the response using below code, but the page doesn’t load at all.
HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
Console.WriteLine("Content length is {0}", response.ContentLength);
Console.WriteLine("Content type is {0}", response.ContentType);
Use the GetResponse method of your HttpWebRequest object (which you named “myRequest”).