// Adds item to cart, stores cookies in TaskInfo, // those cookies have informations about items // that are put in cart // returns false if failed private bool addToCart(ShopItemInfo itemInfo, TaskInfo ti, TaskItemInfo tii) { forwardMessageToLogMonitor(Properties.Resources.logAdding + " " + itemInfo.name + " " + Properties.Resources.logToCart, ti.name); SupremeParser parser = new SupremeParser(); // get url of the chosen item var itemUrl = "http://www.supremenewyork.com" + itemInfo.url; ti.lastItemUri = itemUrl; // referer for checkout var responseItemHTML = WebTools.GetPageHTML(itemUrl, cookies[ti.name], (ProxyInfo)infoManager.GetProxyByName(ti.proxyName)); string itemAddUrl = "https://www.supremenewyork.com" + parser.GetItemCartAddUrl(responseItemHTML); String style = parser.GetItemStyleId(responseItemHTML, tii); String size = parser.GetItemSizeIdFromPage(responseItemHTML, tii); String csrf_token = new Regex("<meta name=\"csrf-token\" content=\"([^\"]*)\"").Match(responseItemHTML).Groups[1].Value; //FileLogger.log("ItemUri: " + itemUrl + "\n"); //FileLogger.log("Style: " + style + " Size: " + size + "\n"); //FileLogger.log("PostUri: " + itemAddUrl + "\n"); if (style == null || size == null) { forwardMessageToLogMonitor(Properties.Resources.logItemNotAvailable, ti.name); return(false); } string postString = PostStringGenerator.generateAddCartPostString(size, style); HttpWebRequest req = (HttpWebRequest)WebRequest.Create(itemAddUrl); req.Referer = itemUrl; req.Method = "POST"; req.Accept = "*/*;q=0.5, text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"; req.Headers["x-csrf-token"] = csrf_token; req.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"; // utf8 del req.ContentLength = postString.Length; req.CookieContainer = cookies[ti.name]; WebTools.setProxy((ProxyInfo)infoManager.GetProxyByName(ti.proxyName), req); // as postWriter doesn't actually send any data, we only need to make sure that GetResponse is going good. StreamWriter postWriter = new StreamWriter(req.GetRequestStream()); postWriter.Write(postString); postWriter.Close(); //MSDOC //The GetResponse method sends a request to an Internet resource and returns a WebResponse instance. //If the request has already been initiated by a call to GetRequestStream, the GetResponse method //completes the request and returns any response. \|/ var res = WebTools.SendRequestAtAllCosts(req); res.Close(); // it takes ~7ms to read the response, but well, we don't need it here, we just need cookiez foreach (var cookie in cookies[ti.name].GetCookies(new Uri("http://www.supremenewyork.com"))) { Console.WriteLine(cookie.ToString()); } //cookies are now in CookieContainer which is a reference for cookies[ti.number] ( no need to save them ) forwardMessageToLogMonitor(Properties.Resources.logSuccessfullyAdded + " " + itemInfo.name + " " + Properties.Resources.logToCart, ti.name); return(true); }