How to use HttpWebRequest to send POST request to another web server
>> Monday, August 2, 2010 –
Exploratory Testing,
Testing
Yesterday we went to MySchools office. A big discussion was going on some database locking issue. It's interesting, their problem is application able to process two transaction successfully, from the third it is locking the table and execution is getting failed with timeout error. We asked to open the code, and we verified further. Finally I found the cause. Close statement is missing in the code. :-)
The Code which helped me to resolve the issue
private void OnPostInfoClick(object sender, System.EventArgs e)Read more...
{
string strId = UserId_TextBox.Text;
string strName = Name_TextBox.Text;
ASCIIEncoding encoding=new ASCIIEncoding();
string postData="userid="+strId;
postData += ("&username="+strName);
byte[] data = encoding.GetBytes(postData);
// Prepare web request...
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("http://localhost/MyIdentity/Default.aspx");
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();}
Subscribe to:
Posts (Atom)