public bool Login(string login, string password) { AvitoWebClient web = new AvitoWebClient(new CookieContainer()); web.Headers.Add("Content-Type", "multipart/form-data; boundary=bound"); web.Headers.Add("Referer", "https://www.avito.ru/profile/login?next=%2Fprofile"); string data = "--bound\n" + "Content-Disposition: form-data; name=\"next\"\n" + "\n" + "/profile\n" + "--bound\n" + "Content-Disposition: form-data; name=\"login\"\n" + "\n" + "[email protected]\n" + "--bound\n" + "Content-Disposition: form-data; name=\"password\"\n" + "\n" + "kirillov4ever\n" + "--bound\n"; try { web.UploadString("https://www.avito.ru/profile/login", data); } catch(Exception e) { return false; } creds = web.Container.GetCookies(new Uri("http://www.avito.ru")); return true; }
public bool Login(string login, string password) { AvitoWebClient web = new AvitoWebClient(new CookieContainer()); web.Headers.Add("Content-Type", "multipart/form-data; boundary=bound"); web.Headers.Add("Referer", "https://www.avito.ru/profile/login?next=%2Fprofile"); string data = "--bound\n" + "Content-Disposition: form-data; name=\"next\"\n" + "\n" + "/profile\n" + "--bound\n" + "Content-Disposition: form-data; name=\"login\"\n" + "\n" + "[email protected]\n" + "--bound\n" + "Content-Disposition: form-data; name=\"password\"\n" + "\n" + "kirillov4ever\n" + "--bound\n"; try { web.UploadString("https://www.avito.ru/profile/login", data); } catch (Exception e) { return(false); } creds = web.Container.GetCookies(new Uri("http://www.avito.ru")); return(true); }
public bool Delete(int id) { AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Headers.Add("Referer", oldItemsUrl); web.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); try { web.UploadString(oldItemsUrl, String.Format(deleteMask, id.ToString())); } catch (Exception e) { return false; } return true; }
public bool Delete(int id) { AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Headers.Add("Referer", oldItemsUrl); web.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); try { web.UploadString(oldItemsUrl, String.Format(deleteMask, id.ToString())); } catch (Exception e) { return(false); } return(true); }
public bool Post(Advertisement ad) { Dictionary <string, string> data = new Dictionary <string, string>(); data.Add("seller_name", ad.User.Name); data.Add("manager", (ad.User.Manager == null) ? "" : ad.User.Manager); data.Add("phone", ad.User.Phone); data.Add("email", ad.User.Email); data.Add("allow_mails", (ad.User.DenyEmails) ? "1" : ""); data.Add("location_id", ad.Location.City.Id.ToString()); data.Add("metro_id", (ad.Location.Metro == null) ? "" : ad.Location.Metro.Id.ToString()); data.Add("district_id", (ad.Location.District == null) ? "" : ad.Location.District.Id.ToString()); data.Add("road_id", (ad.Location.Road == null) ? "" : ad.Location.Road.Id.ToString()); data.Add("category_id", ad.CategoryId.ToString()); foreach (KeyValuePair <int, int> x in ad.Parameters) { data.Add("params[" + x.Key.ToString() + "]", x.Value.ToString()); } data.Add("title", ad.Title); data.Add("description", ad.Body); if (ad.Coordinates != null) { data.Add("coords[lat]", ad.Coordinates.Latitude); data.Add("coords[lng]", ad.Coordinates.Longitude); data.Add("coords[zoom]", ad.Coordinates.Zoom); } data.Add("price", ad.Price.ToString()); data.Add("service_code", "free"); data.Add("main_form_submit", "Продолжить с пакетом «Обычная продажа»"); foreach (Image image in ad.Images) { data.Add("images[]", PostImage(image)); } AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); web.Headers.Add("Referer", url1); try { web.UploadString(url1, Stringify(data)); } catch (Exception ex) { throw new AvitoNetworkException(); } if (!web.ResponseUrl.Contains("confirm")) { throw new WrongAdvertisementException(); } string date = ((int)((DateTime.Now - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds)).ToString(); HttpWebRequest req = HttpWebRequest.Create(captchaUrl + date) as HttpWebRequest; req.Referer = url2; req.CookieContainer = auth.CredsCont; HttpWebResponse res; try { res = req.GetResponse() as HttpWebResponse; } catch (Exception ex) { return(false); } Image im = new Bitmap(res.GetResponseStream()); string cap; try { cap = captcha.GetCaptcha(im); } catch (Exception ex) { return(false); } data.Clear(); data.Add("captcha", cap); data.Add("service", "0"); data.Add("subscribe-position", "0"); web.Headers.Add("Referer", url2); web.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); try { web.UploadString(url2, Stringify(data)); } catch (Exception ex) { throw new AvitoNetworkException(); } if (!web.ResponseUrl.Contains("finish")) { throw new CaptchaException(); } return(true); }
public bool Post(Advertisement ad) { Dictionary<string, string> data = new Dictionary<string, string>(); data.Add("seller_name", ad.User.Name); data.Add("manager", (ad.User.Manager == null) ? "" : ad.User.Manager); data.Add("phone", ad.User.Phone); data.Add("email", ad.User.Email); data.Add("allow_mails", (ad.User.DenyEmails) ? "1" : ""); data.Add("location_id", ad.Location.City.Id.ToString()); data.Add("metro_id", (ad.Location.Metro == null) ? "" : ad.Location.Metro.Id.ToString()); data.Add("district_id", (ad.Location.District == null) ? "" : ad.Location.District.Id.ToString()); data.Add("road_id", (ad.Location.Road == null) ? "" : ad.Location.Road.Id.ToString()); data.Add("category_id", ad.CategoryId.ToString()); foreach (KeyValuePair<int, int> x in ad.Parameters) { data.Add("params[" + x.Key.ToString() + "]", x.Value.ToString()); } data.Add("title", ad.Title); data.Add("description", ad.Body); if (ad.Coordinates != null) { data.Add("coords[lat]", ad.Coordinates.Latitude); data.Add("coords[lng]", ad.Coordinates.Longitude); data.Add("coords[zoom]", ad.Coordinates.Zoom); } data.Add("price", ad.Price.ToString()); data.Add("service_code", "free"); data.Add("main_form_submit", "���������� � ������� �������� �������"); foreach (Image image in ad.Images) data.Add("images[]", PostImage(image)); AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); web.Headers.Add("Referer", url1); try { web.UploadString(url1, Stringify(data)); } catch (Exception ex) { throw new AvitoNetworkException(); } if (!web.ResponseUrl.Contains("confirm")) throw new WrongAdvertisementException(); string date = ((int)((DateTime.Now - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds)).ToString(); HttpWebRequest req = HttpWebRequest.Create(captchaUrl + date) as HttpWebRequest; req.Referer = url2; req.CookieContainer = auth.CredsCont; HttpWebResponse res; try { res = req.GetResponse() as HttpWebResponse; } catch (Exception ex) { return false; } Image im = new Bitmap(res.GetResponseStream()); string cap; try { cap = captcha.GetCaptcha(im); } catch (Exception ex) { return false; } data.Clear(); data.Add("captcha", cap); data.Add("service", "0"); data.Add("subscribe-position", "0"); web.Headers.Add("Referer", url2); web.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); try { web.UploadString(url2, Stringify(data)); } catch (Exception ex) { throw new AvitoNetworkException(); } if (!web.ResponseUrl.Contains("finish")) throw new CaptchaException(); return true; }