public void TestRequest() { var url = "http://baidu.com"; var requester = new HttpRequester(url); requester.Start(); var lastProgress = -1d; while (!requester.IsFinished) { if (!lastProgress.Equals(requester.Progress)) { Console.WriteLine("Progress: {0}", requester.Progress); lastProgress = requester.Progress; } Thread.Sleep(1); } var str = Encoding.UTF8.GetString(requester.DataBytes); Console.WriteLine(str); Assert.Null(requester.Error); Assert.AreNotEqual(null, requester.DataStream); Assert.True(requester.DataStream.Length > 0); }
public void TestRequsterAsyncHook() { var zipUrl = "http://sjres.icantw.com/g1-resources-package/trunk/g1.resources.trunk.1.3.0.3.zip"; var req = new HttpRequester(zipUrl); req.BeforeReadAsyncHook = (req11, doRead, doStop) => { Assert.Greater(req.TotalSize, 0); doStop(); }; req.Start(); while (!req.IsFinished) { Thread.Sleep(1); } Assert.True(req.Error is CancelException); var req2 = new HttpRequester(zipUrl); req2.BeforeReadAsyncHook = (req22, doRead, doStop) => { doRead(); // do nothing, begin read }; req2.Start(); while (!req2.IsFinished) { Thread.Sleep(1); } Assert.False(req2.IsError); }
protected internal override void Start() { _md5FileUrl = _downloader.GetFullUrl() + ".md5"; var request = new HttpRequester(_md5FileUrl); request.SetFinishCallback(OnFinishRequest); request.Start(); }
public void Start() { if (!Directory.Exists(_pullerMetaFolderPath)) { Directory.CreateDirectory(_pullerMetaFolderPath); } _headerRequest = new HttpRequester(_url); _headerRequest.SetRequestMethod("HEAD"); _headerRequest.SetFinishCallback(OnHeaderRequestFinish); _headerRequest.Start(); }
public void TestRequestHead() { using (var req = new HttpRequester("http://www.baidu.com")) { req.SetRequestMethod("HEAD"); req.Start(); while (!req.IsFinished) { Thread.Sleep(1); } Assert.True(req.Response.Headers.Count > 0); Assert.True(req.Response.LastModified.Year > 1970); } }
protected internal override void Start() { if (DebugVersionResult != null) { Result = DebugVersionResult.Value; Finish(); return; } var url = BuildUrl(_versionFileName); Url = url; _req = new HttpRequester(Url); _req.SetFinishCallback(OnFninshedRequest); _req.Start(); }