public static string GetHtmlAsync(string url, string postdata, DownloadMethod method) { WebDownLoader info = new WebDownLoader(); info.Url = url; info.Method = method; info.PostData = postdata; return(GetHtmlAsync(info)); }
public static string GetHtml(string url, string postdata, DownloadMethod method) { WebDownLoader info = new WebDownLoader(); info.Url = url; info.Method = method; info.PostData = postdata; info.ConnectionTimeout = new TimeSpan(0, 10, 0); return(GetHtml(info)); }
public static string GetHtmlAsync(WebDownLoader info) { string html = ""; RequestState <string> requestState = new RequestState <string>(); requestState.Complete = (request) => { html = requestState.RequestData.ToString(); }; info.DownloadAsync <string>(requestState); return(html); }
public static string GetHtml(WebDownLoader info) { string html = string.Empty; RequestState <string> requestState = new RequestState <string>(); requestState.Retry = 5; requestState.Complete = (request) => { html = request.RequestData.ToString(); }; info.Download <string>(requestState); return(html); }
public static string GetImage(string url, string path) { string imagepath = ""; WebDownLoader info = new WebDownLoader(); info.Url = url; info.Method = DownloadMethod.GET; RequestState <string> requestState = new RequestState <string>(); requestState.Retry = 15; if (!DirectoryHelper.CreateDir(path)) { return("path create fail"); } requestState.Complete = (request) => { byte[] data; if (request.StreamResponse != null) { using (var stream = request.StreamResponse) { using (MemoryStream ms = new MemoryStream()) { Byte[] buffer = new Byte[1024]; int current = 0; while ((current = stream.Read(buffer, 0, buffer.Length)) != 0) { ms.Write(buffer, 0, current); } data = ms.ToArray(); } } string filename = path + "\\" + Guid.NewGuid().ToString() + url.Substring(url.LastIndexOf('.')); if (FileHelper.WriteFile(data, filename)) { imagepath = filename; } } }; info.DownloadImage <string>(requestState); return(imagepath); }