static void Main(string[] args) { if (args.Any()) { var folderName = ""; var url = ""; var al = args.ToList(); if (al.Any(x => x == "-u")) { url = al.ElementAt(al.IndexOf("-u") + 1); folderName = url.Replace("http://", "") .Replace("https://", "") .Replace("/", ""); var client = new SharpHttpClient(); client.SetUserAgent(UserAgent.BAIDU_SPIDER); if (_downloader == null) { _downloader = new Downloader.Downloader(client, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, folderName), url); _downloader.DownloadSite(); } } } }
private async void BtnBeginDownload_Click(object sender, EventArgs e) { btnBeginDownload.Enabled = false; var url = txtBaseUrl.Text; var threadNum = txtMaxThreadNum.Text; var tn = 0; int.TryParse(threadNum, out tn); if (tn == 0) { tn = 5; } var client = new SharpHttpClient(); if (string.IsNullOrEmpty(url)) { MessageBox.Show("URL 不能为空"); btnBeginDownload.Enabled = true; return; } if (_downloader == null) { _downloader = new Downloader.Downloader(client, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, new Uri(url).Host), url); } _downloader.Stop = false; _downloader.DownloadImgs = false; await Task.Run(() => { _downloader.DownloadSite(ShowInfo); }); btnBeginDownload.Enabled = true; }
public void TestMethod1() { var client = new SharpHttpClient(); var task = client.GetAsync("https://www.baidu.com"); task.Wait(); }
public void TestMethod1() { var uri = new Uri("http://whwdev03.ciic.com:8082/index.php/bug/list/29?query_id=-2"); var t1 = Path.Combine("c://abc", "ef"); var t2 = Path.Combine("c://abc", "/ef"); var client = new SharpHttpClient(); //client.SetProxy("127.0.0.1", 8087); //client.UserProxy = false; //client.SetUserAgent(UserAgent.BAIDU_SPIDER); var task = client.GetAsync("http://ai010.top/forum.php?mod=viewthread&tid=455674&extra=page%3D1&mobile=2"); task.Wait(); Assert.Equals(task.Result.StatusCode, HttpStatusCode.OK); }