本文介绍了如何读取发布到url的xml数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在3.5 .net框架中有一个asp.net Web应用程序。

一些XML数据发布到我们的Web应用程序的URL中。

如何从网址读取这些xml数据?



提前致谢,

George nt。

Hi All,
I have a asp.net web application in 3.5 .net framework.
Some XML data is posted to a url in our web application.
How to read those xml data from url?

Thanks in advance,
George n t .

推荐答案



//This method will return the XMLdocument fetched from the provided URL
public XmlDocument GetXmlFromUrl(string url)
{
    //requesting the URL 
    var httpRequest = (HttpWebRequest)WebRequest.Create(url);

    //response from the request url is fetched
    var response = (HttpWebResponse)httpRequest.GetResponse();

    //Store the contents of the response in the stream(there are also other options)
    var receivedDataStream = response.GetResponseStream();

    //New XMLdocument
    var xmlFetchedData = new XmlDocument();

    //load the file from the stream
    xmlFetchedData.Load(receivedDataStream);

    //close the stream
    receivedDataStream.Close();

    return xmlFetchedData;
}





注意:您必须包含必要的库



如需进一步阅读: []



[]


这篇关于如何读取发布到url的xml数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 20:41
查看更多