500 error when trying to do a post

  • Thread starter Thread starter Brian
  • Start date Start date
B

Brian

I'm trying to do a POST using the following code, but I'm getting a
500 error. Can somebody please help me? I'm been stuck for quite a
while.


private void bnInvoke_Click(object sender, System.EventArgs e)
{
string lcUrl = "http://www.xmlwebservices.cc/ws/v1/calc/SimpleCalc.asmx/Add";


HttpWebRequest loHttp = (HttpWebRequest) WebRequest.Create(lcUrl);


// *** Send any POST data

string lcPostData = "a=" + HttpUtility.UrlEncode("4") + "&b=" +
HttpUtility.UrlEncode("5") ;

loHttp.Method="POST";

byte [] lbPostBuffer =
System.Text.Encoding.GetEncoding(1252).GetBytes(lcPostData);
loHttp.ContentLength = lbPostBuffer.Length;
Stream loPostData = loHttp.GetRequestStream();
loPostData.Write(lbPostBuffer,0,lbPostBuffer.Length);
loPostData.Close();
HttpWebResponse loWebResponse = (HttpWebResponse)
loHttp.GetResponse();

Encoding enc = System.Text.Encoding.GetEncoding(1252);
StreamReader loResponseStream = new
StreamReader(loWebResponse.GetResponseStream(),enc);
string lcHtml = loResponseStream.ReadToEnd();
loWebResponse.Close();
loResponseStream.Close();

tbResult.Text = lcHtml;
}
 
Are you able to get to that page in the browser? I'm getting a 500 error in
IE.

You might want to make sure you have a working Web service before going
further.
 
Back
Top