So I've got this code, which ideally must not change. On my test site, this code executes fine and posts new data into the database. But on the live site I get the below error. Can anyone advise on what this might be?
protected void Button1_Click(object sender, EventArgs e)
{
WebRequest req = null;
WebResponse rsp = null;
// try
// {
string fileName = Server.MapPath("ExampleXML.xml");
string uri = "http://XXX/api/index.aspx";
req = WebRequest.Create(uri);
//req.Proxy = WebProxy.GetDefaultProxy(); // Enable if using proxy
req.Method = "POST"; // Post method
req.ContentType = "text/xml"; // content type
// Wrap the request stream with a text-based writer
StreamWriter writer = new StreamWriter(req.GetRequestStream());
// Write the XML text into the stream
writer.WriteLine(this.GetTextFromXMLFile(fileName));
writer.Close();
// Send the data to the webserver
rsp = req.GetResponse();
// }
// catch (WebException webEx)
// {
// }
// catch (Exception ex)
// {
// }
// finally
//{
if (req != null) req.GetRequestStream().Close();
if (rsp != null) rsp.GetResponseStream().Close();
//}
}
The error on the live site only is:-
Server Error in '/' Application.
Cannot send a content-body with this verb-type.
Line 47: // finally
Line 48: //{
Line 49: if (req != null) req.GetRequestStream().Close();
Line 50: if (rsp != null) rsp.GetResponseStream().Close();
Line 51: //}
But I am sending a POST request, and this works on my test site, just not the live site. I've ensured the code is copied over and all the files exist.
Why would this code work on one and not the other?
Cheers, Mike.