簡體   English   中英

在Net-Core控制台應用程序中檢索遠程xml文件

[英]Retrieve remote xml file in net-core console app

我正在將一個小型.net應用程序移植到.net核心控制台項目。 在我的舊項目中,我有:

XDocument xml = XDocument.Load(@"c:\path\file.xml")
IEnumerable<Car> cars = from car in xml.Root.Descendants("car")
select new Car
{
    CarId = car.Element("Car_ID")?.Value,
    Make = car.Element("Car_Make")?.Value,
    Model = car.Element("Car_Model")?.Value
}
// do something with cars list

在.net-core中也可以正常工作,但是在我的.net-core項目中,我們需要使用遠程xml文件。 如果我使用網址而不是本地文件路徑,如下所示:

XDocument xml = XDocument.Load(@"https://website/file.xml")

...然后我得到一個錯誤:

The Uri parameter must be a file system relative or absolute path

我發現很多使用XmlDocument和文件流的示例,但是它們要么沒有在.net-core中進行編譯,要么不夠完善,無法幫助我。

使這項工作需要什么?

*編輯以添加更多細節

看一下使用HTTPClient的方法: https ://docs.microsoft.com/zh-cn/dotnet/csharp/tutorials/console-webapiclient

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM