Reputation: 1664
I'm using Amazon API to generate request for ItemLookup. After signing the request I got a url:
Which I use in browser and I can see nice xml with item's data, but When I try to get that data with c# I get error
The Uri parameter must be a file system relative or absolute path.
The method I'm using to get data is:
var itemXml = XElement.Load(url);
How can I get that xml in c#??
Upvotes: 1
Views: 3142
Reputation: 38529
This is nothing .net core specific.
XElement.Load
accepts a string - which, if you look at the intellisense states:
Loads an XElement from a file.
This isn't what you want. It's trying to resolve the URI from the filesystem.
You'll need to read the URL content into a Stream.
Try the following
var httpClient = new HttpClient();
var result = httpClient.GetAsync(url).Result;
var stream = result.Content.ReadAsStreamAsync().Result;
var itemXml = XElement.Load(stream);
Note I've used .Result
- I would recommend instead using await
(async/await) pattern
Upvotes: 6