public static HttpServer HarToHttpServer(HarRequest request) { var r = new HttpServer(); //r.Host = request.header["Host"]; r.UserAgent = request.headers.FirstOrDefault(x => x.name.ToLower() == "User-Agent".ToLower())?.value; r.Accept = request.headers.FirstOrDefault(x => x.name.ToLower() == "Accept".ToLower())?.value; r.ContentType = request.headers.FirstOrDefault(x => x.name.ToLower() == "Content-Type".ToLower())?.value; r.Allowautoredirect = request.Allowautoredirect; r.Referer = request.headers.FirstOrDefault(x => x.name.ToLower() == "Referer".ToLower())?.value; r.PostEncoding = request.PostEncoding; r.Method = request.method; r.Url = request.url; r.PostData = request.postData?.text; foreach (var item in request.headers) { if (string.IsNullOrEmpty(r.HeaderCollection.Get(item.name))) { try { if ("User-Agent,Host,Accept,Connection,Content-Type,Referer,Content-Length".ToLower().Contains(item.name.ToLower())) { continue; } r.HeaderCollection.Add(item.name, item.value); } catch (Exception ex) { } } } return(r); }
public virtual HttpResult GetHttpResult(HarRequest request, CookieContainer cookie = null) { string err; var r = HarToHttpServer(request); HttpResult result = HttpSpider.GetHtmlResult(r, out err); return(result); }
public virtual HttpResult GetHttpResult(HarRequest request, CookieContainer cookie = null) { var r = new HttpServer(); string err; r.Cookies = cookie; r.Host = request.header["Host"]; r.UserAgent = request.header["User-Agent"]; r.Accept = request.header["Accept"]; r.ContentType = request.headers.FirstOrDefault(x => x.name == "Content-Type")?.value; r.Allowautoredirect = request.Allowautoredirect; r.Referer = request.headers.FirstOrDefault(x => x.name == "Referer")?.value; if (cookie == null) { r.Cookies = new CookieContainer(); foreach (var item in request.cookies) { r.Cookies.Add(new Cookie(item.name, item.value) { Domain = r.Host }); } } r.PostEncoding = request.PostEncoding; r.Method = request.method; r.Url = request.url; r.PostData = request.postData?.text; foreach (var item in request.headers) { if (string.IsNullOrEmpty(r.HeaderCollection.Get(item.name))) { try { if ("User-Agent,Host,Accept,Connection,Content-Type,Referer,Content-Length".Contains(item.name)) { continue; } r.HeaderCollection.Add(item.name, item.value); } catch (Exception ex) { } } } HttpResult result = HttpSpider.GetHtmlResult(r, out err); return(result); }