/ / netコアコンソールapp-c#、.net、asp.net-coreでリモートxmlファイルを取得する

net-coreコンソールapp-c#、.net、asp.net-coreでリモートXMLファイルを取得する

私は小さな.netアプリケーションを.netコアのコンソールプロジェクトに移植しています。私の古いプロジェクトでは、私は以下を持っています:

XDocument xml = XDocument.Load(@"c:pathfile.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ファイルで作業する必要があります。ローカルファイルパスの代わりにURLを使用すると、次のようになります。

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

...私はエラーが表示されます:

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

私はXmlDocumentとファイルストリームを使ってたくさんのサンプルを見つけましたが、.net-coreでコンパイルしていないか、私を助けてくれるだけのものではありません。

この仕事をするためには何が必要ですか?

*詳細を追加するように編集

回答:

回答№1は1

HTTPClientの使用を見てみましょう: https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/console-webapiclient