/* csc /target:exe Amazon.cs csc /target:library Amazon.cs */ using System; using System.Net; namespace com.ignitionlabs.utilities { public class Amazon { public static void Main(String[] args) { if (args.Length > 0) { if (args[0] == "HasImage") { String url = ""; if (args.Length == 1) { url = "http://images.amazon.com/images/P/0596005423.01.MZZZZZZZ.jpg"; } else { url = args[1]; } if (Amazon.HasImage(url)) { Console.WriteLine("The image " + url + " does exist."); } else { Console.WriteLine("The image " + url + " does not exist."); } } } else { Console.WriteLine("You must select an action:"); Console.WriteLine("hasImage"); } } public static Boolean HasImage(String url) { // assume no image Boolean result = false; try { HttpWebRequest httpImageURL = (HttpWebRequest)WebRequest.Create(url); WebResponse response = httpImageURL.GetResponse(); // for informational purposes, write out the Content-Length & Content-Type Console.WriteLine("Content-Length = " + response.ContentLength ); Console.WriteLine("Content-Type = " + response.ContentType); if (response.ContentType == "image/jpeg") { result = true; } // in a real app, you'd then download the image and save it for future use response.Close(); // catch any and all exceptions.. ignore them } catch { // do nothing, just return false } return result; } } }