我正在从Classic asp调用Web API方法,如下所示。但是我总是在API中而不是XML中获得requestData为空。
调用Web API的经典ASP代码:
var XMLOrder = new ActiveXObject ("Microsoft.XMLDOM");
XMLOrder.load("orderTemplate.xml");
var xHttp = new ActiveXObject("Microsoft.XMLHTTP");
xHttp.Open("POST","http://localhost:18977/SaveActitvityRequest",false);
xHttp.setRequestHeader("CONTENT-TYPE", "application/xml")
xHttp.Send(XMLOrder);
Web API方法:
[Route("SaveActitvityRequest")]
[HttpPost]
public HttpResponseMessage SaveActitvityRequest([FromBody]XDocument requestData)
{
try
{
return null;
}
catch (Exception ex)
{
Logger.Error(ex);
return Request.CreateResponse(HttpStatusCode.BadRequest, ex);
}
}
答案 0 :(得分:1)
requestData可能为null,因为您要发送“ Microsoft.XMLDOM”对象的实例。如果您尝试发送xml,则应该开始工作。将经典ASP的最后一行更改为:
xHttp.Send(XMLOrder.xml);