如果有人将XML从应用程序发布到我的ASP.NET页面,我该如何解析它并以XML格式返回响应?
将XML发布到我的网址的示例客户端代码:
WebRequest req = null;
WebResponse rsp = null;
string uri = "https://beta.abc.company.com/mypage.aspx";
req = WebRequest.Create(uri);
req.Method = "POST";
req.ContentType = "text/xml";
StreamWriter writer = new StreamWriter(req.GetRequestStream());
writer.WriteLine(txtXML.Text.ToString());
writer.Close();
rsp = req.GetResponse();
我如何从mypage.aspx
解析XML并将响应作为XML?
答案 0 :(得分:5)
您可以从请求流中读取XML。所以在mypage.aspx
:
protected void Page_Load(object sender, EventAgrs e)
{
using (var reader = new StreamReader(Request.InputStream))
{
string xml = reader.ReadToEnd();
// do something with the XML
}
}