//Method to take a signed URL and return information contained in the get response
public static string Fetch(string url)
{
string asin = "";
try {
//Makes a request, and exports the response into an XML file
WebRequest request = HttpWebRequest.Create(url);
WebResponse response = request.GetResponse();
XmlDocument doc = new XmlDocument();
doc.Load(response.GetResponseStream());
//Parse XML document for errors
XmlNodeList errorMessageNodes = doc.GetElementsByTagName("Message", NAMESPACE);
if (errorMessageNodes != null && errorMessageNodes.Count > 0) {
String message = errorMessageNodes.Item(0).InnerText;
string error;
MessageBox.Show("Unfortunately, music preview isn't available for this track.");
//MessageBox.Show("Error: " + message + " (but signature worked)");
return null;
}
XmlNode asinNode = doc.GetElementsByTagName("ASIN", NAMESPACE).Item(0);
if (asinNode != null) asin = asinNode.InnerText;
return asin;
}
catch (Exception e) {
System.Console.WriteLine("Caught Exception: " + e.Message);
System.Console.WriteLine("Stack Trace: " + e.StackTrace);
}
return null;
}