问题描述
使用提琴手,我可以通过身体
Using Fiddler I can pass in the body
someXml = ThisShouldBeXml
someXml=ThisShouldBeXml
,然后在控制器中
[HttpPost]
public ActionResult Test(object someXml)
{
return Json(someXml);
}
以字符串形式获取此数据
gets this data as a string
如何使提琴手将XML传递给MVC ActionController?如果我尝试将主体中的值设置为原始xml,则无法正常工作.
How do I get fiddler to pass XML to the MVC ActionController ? If I try setting the value in the body as raw xml it does not work..
要获得奖励积分,如何从VBscript/经典ASP中做到这一点?
And for bonus points how do I do this from 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发布将XML数据作为Stream传递.
You cannot directly pass XML data as file to MVC controller. One of the best method is to pass XML data as Stream with HTTP post.
对于发布XML,
- 将XML数据转换为流并附加到HTTP标头
- 将内容类型设置为"text/xml; encoding ='utf-8'"
有关发布XML的更多详细信息,请参见此stackoverflow帖子到MVC控制器
Refer to this stackoverflow post for more details about posting XML to MVC Controller
要在控制器中检索XML,请使用以下方法
For retrieving XML in the controller, use the following method
[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
}
}
这篇关于如何将XML发布到MVC Controller中? (而不是键/值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!