//do ponownego merga public static void test01() { WebClient wc = new WebClient(); wc.Headers.Add("Content-Type: application/x-www-form-urlencoded"); wc.Headers.Add("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5"); wc.Headers.Add("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); wc.Headers.Add("Accept-Encoding: identity"); wc.Headers.Add("Accept-Language: en-US,en;q=0.8"); wc.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3"); // http://napisy24.pl/search.php?str=piotr+dudzik+%B1%EA%E6+%F3%BF%BC%BFd%F3%F3%F3pa // piotr dudzik ąęć óżźżdóóópa // Console.WriteLine("EscapeDataReplace: " + Uri.EscapeDataString(testString).Replace("%20", "+")); string title = "Hobbit"; string encodedTitle = Uri.EscapeDataString(title).Replace("%20", "+"); string napisyURL = "http://napisy24.pl/search.php?str="; string requestURL = string.Format("{0}{1}", napisyURL, encodedTitle); //string response = wc.DownloadString(requestURL); // http://napisy24.pl/logowanie/ // form_logowanieMail=waaaggh&form_logowanieHaslo=d00pad00pa&form_loginZapamietaj=1&postAction=sendLogowanie string loginData = @"form_logowanieMail=waaaggh&form_logowanieHaslo=d00pad00pa&form_loginZapamietaj=1&postAction=sendLogowanie"; string cookie = string.Empty; //cookie = wc.ResponseHeaders["Set-Cookie"].ToString(); //wc.UploadString("http://napisy24.pl/logowanie/", "POST", loginData); //wc.Headers.Add("Cookie", cookie); //string r1= wc.UploadString("http://napisy24.pl/logowanie/", "POST", loginData); //string DocumentText = wc.DownloadString("http://napisy24.pl/download/67682/"); // The.Hobbit.2012.DVDScr.XVID.AC3.HQ.Hive-CM8.avi // Znaleziono 0 filmów dla "wpisz nazwę filmu basfasfdfądź napisów jakich szukasz " // Nie znaleziono wyników // Znaleziono 2 filmów dla "hobbit " // The Hobbit: An Unexpected Journey // Hobbit: Niezwykła podróż, Hobbit: Nieoczekiwana podróż // DVDRip.XviD-RISES // 06-04-2013 // http://napisy24.pl/download/67682/ CookieAwareWebClient wcc = new CookieAwareWebClient(); wcc.Headers.Add("Content-Type: application/x-www-form-urlencoded"); wcc.Headers.Add("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5"); wcc.Headers.Add("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); wcc.Headers.Add("Accept-Encoding: identity"); wcc.Headers.Add("Accept-Language: en-US,en;q=0.8"); wcc.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3"); //string swcc1 = wcc.DownloadString("http://napisy24.pl/logowanie/"); string swcc2 = wcc.UploadString("http://napisy24.pl/logowanie/", "POST", loginData); cookie = wcc.ResponseHeaders["Set-Cookie"].ToString(); wcc.Headers.Add("Cookie", cookie); wcc.DownloadFile("http://napisy24.pl/download/67682/", @"C:\aaa.zip"); string swcc3 = wcc.DownloadString("http://napisy24.pl/download/67682/"); }
public void SaveLastConsole( string name, string path) { Login(); // http://129.59.105.75:8080/job/[jobName]/lastBuild/consoleText if (JobExists(name)) { try { // TODO: HEAD it and set Timeout appropriately using (CookieAwareWebClient webClient = new CookieAwareWebClient()) { webClient.cookies = AuthCookies; webClient.DownloadFile(ServerUrl + String.Format(Queries.LAST_BUILD_CONSOLE_TEXT, HttpUtility.UrlEncode(name)), path); } } catch (WebException ex) { Console.WriteLine(ex.ToString()); } } }
//TODO: разобраться с возвратом //Подключается к серверу, скачевает xlsx фаил, разархивируетв в xml и десереализует/ public async Task<bool> GetDataFromServer() { //Рабочая часть, соединяемся с сервером и получаем куки var cookie = await GetCookiesAsync("http://bo-otchet.1gl.ru/Account/Login", _loginName, _loginPwd); //Получаем данные с помошью WebClient using (var client = new CookieAwareWebClient(cookie)) { Uri newUri = new Uri("http://bo-otchet.1gl.ru/Registration/RepostRegistrationExcel?Caption=%D0%A1%20%D0%B2%D1%8B%D0%BF%D1%83%D1%89%D0%B5%D0%BD%D0%BD%D0%BE%D0%B9%20%D0%9A%D0%AD%D0%9F&ShowSearchForm=False&PageId=0&PageSize=50&SuppressFlags=0&ViewId=HaveCertificate&PartnerId=" + PartnerId); client.DownloadFile(newUri, $"{_partnerId}.xlsx"); using (ZipFile zip = ZipFile.Read($"{_partnerId}.xlsx")) { if (zip == null) Console.WriteLine("Null"); else { foreach (var zp in zip) { zp.Extract(ExtractExistingFileAction.OverwriteSilently); } } } } ShowMessageClass showMessage = new ShowConsoleMessage(); try { XmlDocument _xml = new XmlDocument(); try { _xml.Load("xl\\worksheets\\sheet1.xml"); } catch (System.IO.FileNotFoundException ex) { showMessage.ShowMessage($"File not found!{Environment.NewLine} Error: {ex.ToString()}"); } string str = _xml.OuterXml; str = str.Replace("<v>", "").Replace("</v>", "") .Replace("<f>=TEXT", "").Replace("</f>", ""); XmlRootAttribute xRoot = new XmlRootAttribute(); xRoot.ElementName = "worksheet"; xRoot.Namespace = "http://schemas.openxmlformats.org/spreadsheetml/2006/main"; xRoot.IsNullable = true; var xml = new XmlSerializer(typeof(Worksheet), xRoot); Data = xml.Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(str))) as Worksheet; return true; } catch (Exception ex) { showMessage.ShowMessage(ex.Message); return false; } }