1
votes

I'm using Amazon API to generate request for ItemLookup. After signing the request I got a url:

http://webservices.amazon.com/onca/xml?AWSAccessKeyId=[AccessKey]&AssociateTag=[AssociateTag]&ItemId=B06XBCY6DW&Operation=ItemLookup&ResponseGroup=Images%2CItemAttributes%2COffers%2CReviews&Service=AWSECommerceService&Timestamp=2050-02-13T12:00:00Z&Version=2016-02-12&Signature=[Signature]

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#??

1
The url is a String I guess? If so, the documentation suggests it should be a file which I interpret as it should be local on your own pc. not sure though msdn.microsoft.com/en-us/library/… - Gert Kommer
@GertKommer yes my url is string, but your given example does not work in asp.net core - Nikas Žalias

1 Answers

6
votes

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