public void Webpage2Test() { var page = new WebPage2(url1); print("Trying to css select the download link: "); page.LoadPage(); string dllink = page.doc_css["a.dev-page-download[href]"].Attr("href"); print(dllink); print("Trying to transfer to the above page: "); var newpage = page.Transfer(dllink); //Using postman default header CustomizedHeaders fun = delegate(HttpRequestHeaders arg) { print("The delegated defined in the test is called. "); arg.Add("Cache-Control", "no-cache"); arg.Add("accept-encoding", "gzip,deflate"); arg.Add("connection", "keepalive"); }; newpage.mlr_thispage.header_customizer = fun; newpage.LoadPage(); print(newpage); print(newpage.response_headers); print(newpage.content_raw_string); }
/// <summary> /// This function cusomized the headers for a new request and transfer /// cookies to the new download url. /// </summary> /// <returns> /// Null if returned if there is something wrong /// </returns> public WebPage Download_Redirect() { string dl = this.GetDownloadLink(); if (dl.Length != 0) { WebPage newpage = this.TransferCookies(dl); //Establish Headers. CustomizedHeaders header_modifier = delegate(HttpRequestHeaders header) { header.Add ( "user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML," + " like Gecko) Chrome/75.0.3770.90 Safari/537.36" ); header.Add ( "accept", "text/html,application/xhtml+xml,application/xml;q=0.9," + "image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3" ); header.Add ( "accept-encoding", "gzip, deflate, br" ); header.Add ( "referer", base_url ); header.Add ( "upgrade-insecure-requests", "1" ); header.Add ( "host", "www.deviantart.com" ); }; newpage.mlr_thispage.header_customizer = header_modifier; return(newpage); } return(null); }