【发布时间】:2015-01-13 16:31:32
【问题描述】:
所以我得到了这段代码,最好不要改变。在我的测试站点上,此代码执行良好并将新数据发布到数据库中。但是在实时站点上,我收到以下错误。谁能建议这可能是什么?
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();
//}
}
仅现场站点上的错误是:-
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: //}
但我正在发送一个 POST 请求,这适用于我的测试站点,而不是实时站点。我已确保复制代码并且所有文件都存在。
为什么这段代码只适用于一个而不适用于另一个?
干杯, 迈克。
【问题讨论】:
-
检查 this SO post 应该会回答您的问题。
-
不幸的是,这并不能解决问题。同样的错误仍然出现在同一个地方。