/// <summary> /// Constructor. /// </summary> /// <param name="protocol">The web protocol (http, https).</param> /// <param name="host">The host name or IP address.</param> /// <param name="port">The port number.</param> public NRestClient(WebProtocol protocol = WebProtocol.http, string host = "localhost", int port = 9000) : base() { this.Protocol = protocol; this.Host = host; this.Port = port; }
public void download(HuashitongPicture picture, string dirpath) { WebProtocol web; //if (dirpath.LastIndexOf('.') > dirpath.LastIndexOf('\\')) //{ dirpath = new DirectoryInfo(dirpath).Parent.Name; } msg.startProcess(0, picture.imgCount, 1, $"正在下载 {picture.title}({picture.picID})({picture.artist})..."); string url; for (int i = 0; i < picture.imgCount; i++) { try { url = picture.link.Replace("p0.jpg", $"p{i}.jpg").Replace("p0.png", $"p{i}.png"); web = new WebProtocol(url); web.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"; web.Headers.Add("pragma", "no-cache"); web.Headers.Add("sec-fetch-dest", "document"); web.Headers.Add("sec-fetch-mode", "navigate"); web.Headers.Add("sec-fetch-site", "none"); web.Headers.Add("sec-fetch-user", "?1"); var bytes = web.contentBytes; var path = dirpath + $"{picture.generateFilename()}_p{i}.{Path.GetExtension(url)}"; File.WriteAllBytes(path, bytes); msg.stepProcess(); } catch (Exception ex) { msg.puts(); msg.error(ex.Message); } } msg.puts(); // msg.puts($"完成! 共[{picture.imgCount}]张图片"); }
public string json(string title, int index = 1) { const string url = "https://rt.huashi6.com/front/works/search?_ts_={ts}&index={index}&title={title}"; title = WebProtocol.EscapeDataString(title); var web = new WebProtocol(url.Replace("{index}", index.ToString()).Replace("{title}", title).Replace("{ts}", _tsParam.ToString())); return(web.contentDocument); }
public List <HuashitongPicture> rankList() { // 每天的排行榜只有50个,可以指定一个json页面返回的数量 string link = $"https://rt.huashi6.com/front/works/rank_page?index=1&size=50&date={DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day}"; var web = new WebProtocol(link); web.Accept = "application/json, text/plain, */*"; web.Headers.Add("sec-fetch-site", "same-site"); web.Headers.Add("sec-fetch-mode", "cors"); web.Headers.Add("sec-fetch-dest", "empty"); var json = web.contentDocument; return(pictureList(json)); }
/// <summary> /// Create new instance of NRestClient. /// </summary> /// <param name="protocol">The web protocol (http, https).</param> /// <param name="host">The host name or IP address.</param> /// <param name="port">The port number.</param> /// <returns>Returns new instance of NRestClient.</returns> public static NRestClient Create(WebProtocol protocol = WebProtocol.http, string host = "localhost", int port = 9000) { return(new NRestClient(protocol, host, port)); }
/// <summary> /// Gets the full URL to some endpoint. (prepends the path with a server domain/ip) /// </summary> /// <returns>The URL.</returns> /// <param name="path">Path.</param> public static string GetUrl(string path, WebProtocol protocol = WebProtocol.https, long serverId = 0) { var protocolName = protocol.ToString(); // Enum.GetName(typeof(WebProtocol), protocol); return($"{protocolName}://{GetUrl((ushort)protocol,serverId)}/{path.TrimStart('/')}"); }