public static void HttpRequesterTest() { //var client = new HttpRequester("https://weihanli.xyz"); //var result = client.Execute(); //Console.WriteLine(result); //client = new HttpRequest(PostUploadFileUrl, HttpMethod.Post); //client.WithFile(@"C:\Users\liweihan.TUHU\Pictures\temp\7604648.jpg"); //result = client.Execute(); //Console.WriteLine(result); //var response1 = new HttpRequester("https://initwords.com/") // .ExecuteForResponse(); //var sessionId = response1.Cookies["JSESSIONID"]?.Value ?? "E641209D81307143F8B2482B7B2C6ED2"; //var client = new HttpRequester("https://initwords.com/login/authless/ajaxLogin.do", HttpMethod.Post); //client // .WithHeaders(new Dictionary<string, string> // { // { "em-tokencode","a287f418-ed57-439c-bdb8-734baa00d9e4" }, // { "em-usercode","a01836e9-f566-46c5-b3df-528c65e78dbd" }, // {"cookie", $"Hm_lvt_49a5957871e8051bc1a873596375812d=1519034509; JSESSIONID=E641209D81307143F8B2482B7B2C6ED2; Hm_lpvt_49a5957871e8051bc1a873596375812d=1519034755" }, // { "origin", "https://initwords.com" }, // { "referer", "https://initwords.com/" }, // { "x-requested-with", "XMLHttpRequest" } // }) // .WithParameters(new Dictionary<string, string> // { // { "loginType", "studentLogin" }, // { "siteName", "xfinit" }, // { "userId", "lby13460426337"}, // { "userPwd", "lby13460426337" } // }) // .WithUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36"); //var response = client.Execute(); //Console.WriteLine(response); var activateClient = new WebRequestHttpRequester("https://initwords.com/book/ajaxRegisterBook.do", HttpMethod.Post); activateClient.WithHeaders(new Dictionary <string, string> { { "em-tokencode", "a287f418-ed57-439c-bdb8-734baa00d9e4" }, { "em-usercode", "a01836e9-f566-46c5-b3df-528c65e78dbd" }, { "cookie", $"Hm_lvt_49a5957871e8051bc1a873596375812d=1519034509; JSESSIONID=E641209D81307143F8B2482B7B2C6ED2; Hm_lpvt_49a5957871e8051bc1a873596375812d=1519034755" }, { "origin", "https://initwords.com" }, { "referer", "https://initwords.com/" }, { "x-requested-with", "XMLHttpRequest" } }) //.WithFormParameters(new Dictionary<string, string> //{ // { "moduleCode", "8a108cb74c7ae17a014c7d671d430771" }, // { "cardNo", "20180218018071452273218" }, // { "cardPwd", "bz6Bj568" }, // { "userCode", "a01836e9-f566-46c5-b3df-528c65e78dbd" } //}) .WithUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36"); var result = activateClient.ExecuteForJson <TempResponseEntity>(); Console.Write(result); }
public static void MainTest() { var result = new WebRequestHttpRequester("https://weihanli.xyz") .WithReferer("https://weihanli.xyz") .WithHeaders(new Dictionary <string, string> { { "Header1", "Header1" } }) .Execute(); System.Console.WriteLine(result); result = new HttpClientHttpRequester() .WithUrl("https://weihanli.xyz") .WithMethod(HttpMethod.Get) .WithReferer("https://weihanli.xyz") .WithHeaders(new Dictionary <string, string> { { "Header1", "Header1" } }) .Execute(); System.Console.WriteLine(result); var loginResult = new WebRequestHttpRequester("https://accounting.weihanli.xyz/Account/LogOn", HttpMethod.Post) .WithHeaders(new Dictionary <string, string>() { // { "X-Requested-With", "XMLHttpRequest" }, { "Header1", "Header1" } }) .AjaxRequest() .WithReferer("https://accounting.weihanli.xyz/Account/Login?ReturnUrl=%2F") .WithUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36") .WithFormParams(new Dictionary <string, string>() { { "Username", "liweihan" }, { "Password", "112233" }, { "RememberMe", "false" } }) .ExecuteForJson <WeihanLi.Common.Models.JsonResultModel <bool> >(); System.Console.WriteLine(loginResult.ToJson()); var uploadFileResponse = new WebRequestHttpRequester("https://graph.baidu.com/upload", HttpMethod.Post) .WithFile($@"{System.Environment.GetEnvironmentVariable("USERPROFILE")}\Pictures\4e6ab53e383863ed4d15252039f70423.jpg", "image", new Dictionary <string, string>() { { "tn", "pc" }, { "from", "pc" }, { "image_source", "PC_UPLOAD_SEARCH_FILE" }, { "range", "{\"page_from\": \"searchIndex\"}" }, }) .WithReferer("https://baidu.com/") .WithUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36") .ExecuteForResponse(); System.Console.WriteLine($"Response status:{uploadFileResponse.StatusCode}, result:{uploadFileResponse.ResponseBytes.GetString()}"); }