用小提琴我可以把身体传进去
somexml=这应该是xml
然后在控制器里

    [HttpPost]
    public ActionResult Test(object someXml)
    {
        return Json(someXml);
    }

将此数据作为字符串获取
如何让fiddler将xml传递给mvc actioncontroller?如果我尝试将正文中的值设置为原始XML,它将不起作用。
为了获得额外的积分,我如何在vbscript/classic asp中完成这项工作?
我现在有
DataToSend = "name=JohnSmith"

          Dim xml
         Set xml = server.Createobject("MSXML2.ServerXMLHTTP")
   xml.Open "POST", _
             "http://localhost:1303/Home/Test", _
             False
 xml.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
 xml.send DataToSend

最佳答案

不能直接将XML数据作为文件传递给MVC控制器。最好的方法之一是使用http post将xml数据作为流传递。
对于发布XML,
将XML数据转换为流并附加到HTTP头
将内容类型设置为“text/xml;encoding='utf-8'”
有关将XML发布到MVC控制器的详细信息,请参阅this stackoverflow post
要在控制器中检索XML,请使用以下方法

[HttpPost]
public ActionResult Index()
{
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

    if (response.StatusCode == HttpStatusCode.OK)
    {
        // as XML: deserialize into your own object or parse as you wish
        var responseXml = XDocument.Load(response.GetResponseStream());

        //in responseXml variable you will get the XML data
    }
}

10-05 21:10
查看更多