public string ExecuteQuery(string url, bool useCookie = true) { WebClientWithCookies client; if (useCookie) { var formatter = new BinaryFormatter(); CookieContainer cc = null; using (Stream s = File.OpenRead(AmazonVideoRequest.cookiePath())) cc = (CookieContainer)formatter.Deserialize(s); client = new WebClientWithCookies(cc); } else { client = new WebClientWithCookies(new CookieContainer()); } //generate a signature for this URL string sig = generate_signature(url); //add this signature as a header client.Headers.Add("x-android-sign", sig); //get the data Stream data = client.OpenRead(url); StreamReader reader = new StreamReader(data); string tmp = reader.ReadToEnd(); //Trace.WriteLine("********Query: " + url + "\r\n***********" + tmp); return(tmp); }
/// <summary> /// requests data optionally using the amazon cookies /// </summary> /// <param name="url"></param> /// <param name="useCookie"></param> /// <returns></returns> public static string getURL(string url, bool useCookie = false) { WebClientWithCookies client; if (useCookie) { var formatter = new BinaryFormatter(); CookieContainer cc = null; using (Stream s = File.OpenRead(cookiePath())) cc = (CookieContainer)formatter.Deserialize(s); client = new WebClientWithCookies(cc); } else { client = new WebClientWithCookies(new CookieContainer()); } //generate a signature for this URL string sig = generate_signature(url); //add this signature as a header client.Headers.Add("x-android-sign", sig); //get the data Stream data = client.OpenRead(url); StreamReader reader = new StreamReader(data); return(reader.ReadToEnd()); }