如果有人将 XML 从应用程序发布到我的 ASP.NET 页面,我如何解析它并以 XML 格式返回响应?
将 XML 发布到我的 URL 的示例客户端代码:
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();
我如何解析 XMLmypage.aspx
并以 XML 形式给出响应?
您可以从请求流中读取 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
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)