public static void ToWebString(this Uri e, Action <string> handler) { var request = new URLRequest(e.ToString()); request.method = URLRequestMethod.GET; var loader = new URLLoader(); loader.complete += args => { handler("" + loader.data); }; loader.ioError += args => { handler(null); }; loader.securityError += args => { handler(null); }; loader.load(request); }
/// <summary> /// get方式请求网址 /// </summary> /// <param name="url"></param> /// <returns></returns> private string doRequest(string url) { URLLoader loader = new URLLoader(); string response = loader.RequestByUTF8(url); return(response); }
public ServicesHolder(IReadOnlyList <IServices> services) { for (int i = 0; i < services.Count; i++) { // Put in here services // Can be more optimized than that, but I don't have time if (sceneService == null) { sceneService = services[i] as SceneManagementService; } if (jsonConverter == null) { jsonConverter = services[i] as IConverter; } if (webLoader == null) { webLoader = services[i] as URLLoader; } if (bundleService == null) { bundleService = services[i] as BundleService; } } }
/// <summary> /// 启动去采集单本书 /// </summary> /// <param name="url"></param> private static void _startCollectionTaskSort(object o) { KeyValuePair <string, string> pair = (KeyValuePair <string, string>)o; string sortUrl = pair.Key; string sortName = pair.Value; //读取分类下的数据,提取分类里的url信息 URLLoader UrlLoader = new URLLoader(); var result = UrlLoader.RequestByGBK(sortUrl); HtmlDocument document = new HtmlDocument(); document.LoadHtml(result); var documentNode = document.DocumentNode; HtmlNodeCollection linkNodes = documentNode.SelectNodes("//div[@class='title-info']/h2"); List <string> list = new List <string>(); foreach (var liNode in linkNodes) { var title = liNode.SelectSingleNode("a")?.InnerText; var url = liNode.SelectSingleNode("a")?.GetAttributeValue("href", ""); list.Add(url); } foreach (var item in list) { WorkerController controller = new WorkerController(sortName, item); controller.Execute(interval); } }
public void SetHttpHeader(string key, string value) { if (UrlLoader == null) { UrlLoader = new URLLoader(); } UrlLoader.SetHttpHeader(key, value); }
/************************************/ public void SetUserAgent(string userAgent) { if (UrlLoader == null) { UrlLoader = new URLLoader(); } UrlLoader.SetUserAgent(userAgent); }
public void SetAccept_Encoding(string value) { if (UrlLoader == null) { UrlLoader = new URLLoader(); } UrlLoader.SetHttpHeader("Accept-Encoding", value); }
public virtual void SetPostBody(string post) { if (UrlLoader == null) { UrlLoader = new URLLoader(); } UrlLoader.SetPostBody(post); }
public void SetCookie(string cookie) { if (UrlLoader == null) { UrlLoader = new URLLoader(); } UrlLoader.SetHttpHeader("Cookie", cookie); }
public IURLLoader asynLoad(string url, ListenDelegate dele, bool autoDelete, bool errNotify) { url = url.Trim(); if ("" == url || false == url.EndsWith(".u3d")) { throw new Exception("AsynResourceMgr -> ansynLoad() -> url[" + url + "] is empty or not end with .u3d"); } // if (!_URLLoaders.ContainsKey(url)) { URLLoader lo = new URLLoader(); lo.url = url; if (fileVers.ContainsKey(url)) { lo.fileVersion = fileVers[url]; } lo.fullUrl = fullUrl(url, lo.fileVersion); _URLLoaders.Add(url, lo); // Debug.Log("=============== url: "+url+" verson: "+lo.fileVersion+" ============="); } URLLoader loader = _URLLoaders[url] as URLLoader; // add listener loader.addListener(dele, errNotify); // auto delete if (loader.autoDelete == true) { loader.autoDelete = autoDelete; } if (_delayAutoDelete) { loader.preventAutoDelete = true; } URLLoaderState state = loader.state; if (state == URLLoaderState.unload) { putinWaitingList(loader); fullDownload(); } else if (state == URLLoaderState.waiting || state == URLLoaderState.loading) { //nothing } else if (state == URLLoaderState.loaded || state == URLLoaderState.error) { //enter to notify list, next update to notify user _notifyList.Add(loader); } return(loader); }
// void putinWaitingList(URLLoader loader) { if (loader.state != URLLoaderState.unload) { throw new ArgumentOutOfRangeException("loader.state", "state must be URLLoaderState.unload"); } loader.state = URLLoaderState.waiting; _waitingQueue.Add(loader); }
// public bool hasCompleteLoader(string url) { if (_URLLoaders.ContainsKey(url)) { URLLoader loader = _URLLoaders[url] as URLLoader; if (loader.state == URLLoaderState.loaded) { return(true); } } return(false); }
public URL_LoaderHandler(Instance instance, string url) { this.instance = instance; this.url = url; urlRequest = new URLRequestInfo(instance); urlLoader = new URLLoader(instance); urlRequest.SetURL(url); urlRequest.SetMethod("GET"); urlRequest.SetRecordDownloadProgress(true); urlRequest.SetFollowRedirects(true); }
// Update is called once per frame void Update() { if (!testRan && TestInRelease && ParseManager.DoneInstantiating && URLLoader.DoneInstatiating) { if (!Application.isEditor && !TestInRelease) { return; } testRan = true; URLLoader.BuildURL(URLLoader.GetDataFrom(TestURL + "?" + TestCode).ToArray()); CBUG.Do("Retrieved URL: " + URLLoader.URL); } }
public void destroyLoader(string url, bool unloadAllLoadedObjects, bool omitNotify) { if (!_URLLoaders.ContainsKey(url)) { return; } URLLoader loader = _URLLoaders[url] as URLLoader; destroyLoader(loader, unloadAllLoadedObjects, omitNotify); //full download fullDownload(); }
/// <summary> /// post方式提交数据 /// </summary> /// <param name="url"></param> /// <param name="smodel"></param> /// <returns></returns> private string doPost(string url, object smodel) { string jsonstr = JsonConvert.SerializeObject(smodel); jsonstr = HttpUtility.UrlEncode(jsonstr, System.Text.Encoding.UTF8); URLLoader loader = new URLLoader(); loader.SetPostBody(jsonstr); string response = loader.RequestByUTF8(url); return(response); }
void MakeLink() { Debug.Log("making link"); //dispPt.Time = //URLLoader.DataPoint StartPoint = new DataPoint(mylabel, mytime, mycitycode, mystatecode); //URLLoader.DataPoint EndPoint = new DataPoint(mylabel, mytime, mycitycode, mystatecode); URLLoader.BuildURL(dispPt, startPt, endPt); //URLLoader.BuildURL //DataPoint(string Time, string CityCode, string StateCode, string TruckID) }
void destroyLoader(URLLoader loader, bool unloadAllLoadedObjects, bool omitNotify) { if (!omitNotify && loader.listeners.Count != 0) { throw new InvalidOperationException("destroyLoader error: url '" + loader.url + "' has some user to notify!"); } _waitingQueue.Remove(loader); _downloadList.Remove(loader); _notifyList.Remove(loader); // _URLLoaders.Remove(loader.getUrl()); //destroy self loader.destroySelf(unloadAllLoadedObjects); }
/// <summary> /// Default constructor /// </summary> public URLRequestHeaderExample() { // http://livedocs.adobe.com/flex/3/langref/flash/net/URLRequestHeader.html#includeExamplesSummary // http://www.judahfrangipane.com/blog/?p=87 var t = new TextField { multiline = true, text = "powered by jsc", background = true, width = 400, x = 8, y = 8, alwaysShowSelection = true, }.AttachTo(this); var loader = new URLLoader(); var header = new URLRequestHeader("XMyHeader", "got milk?"); t.appendText("\n" + this.loaderInfo.url); t.appendText("\nUsing relative path..."); var request = new URLRequest("../WebForm1.aspx"); var data = new DynamicContainer { Subject = new URLVariables("name=John+Doe") }; data["age"] = 23; request.data = data.Subject; request.method = URLRequestMethod.POST; request.requestHeaders.push(header); loader.complete += args => { t.appendText("\n" + loader.data); }; loader.load(request); KnownEmbeddedResources.Default[KnownAssets.Path.Assets + "/Preview.png"].ToBitmapAsset().AttachTo(this).MoveTo(100, 200); }
public void DownloadStringAsync(Uri address) { // testedby // X:\jsc.svn\examples\actionscript\Test\TestWebClient\TestWebClient\ApplicationSprite.cs var request = new URLRequest(address.ToString()) { method = URLRequestMethod.GET }; var loader = new URLLoader(); loader.complete += args => { var e = new __DownloadStringCompletedEventArgs { Result = "" + loader.data }; DownloadStringCompleted(this, (DownloadStringCompletedEventArgs)(object)e); }; loader.ioError += args => { var e = new __DownloadStringCompletedEventArgs { Error = new Exception("ioError") }; DownloadStringCompleted(this, (DownloadStringCompletedEventArgs)(object)e); }; loader.securityError += args => { var e = new __DownloadStringCompletedEventArgs { Error = new Exception( "securityError " + new { args.errorID, args.text } ) }; DownloadStringCompleted(this, (DownloadStringCompletedEventArgs)(object)e); }; loader.load(request); }
public int removeDelegate(string url, ListenDelegate dele) { if (!_URLLoaders.ContainsKey(url)) { return(0); } URLLoader loader = _URLLoaders[url] as URLLoader; int count = loader.removeListener(dele); //no listener, auto delete, in waiting list. Destroy immediately, Avoid to download! if (loader.listeners.Count == 0 && loader.isAutoDelete() && loader.state == URLLoaderState.waiting) { destroyLoader(loader, false, false); } return(count); }
// distribute to user that resource is loaded // General, it calls by manager. public void distribute() { while (_notifyList.Count != 0) { URLLoader loader = _notifyList[0] as URLLoader; // This laoder is out of relation with _notifyList, first. // In "ls.dele(loader);", you may destroy this loader, this way, you could not raise an error. _notifyList.RemoveAt(0); if (loader.state != URLLoaderState.loaded && loader.state != URLLoaderState.error) { throw new ArgumentOutOfRangeException("loader.state", "state must be loaded or error"); } //foreach(URLLoader.Listener ls in loader.listeners) // "ls.dele(loader);" may be destroy this loader; while (loader.state != URLLoaderState.destroyed && loader.listeners.Count != 0) { URLLoader.Listener ls = loader.listeners[0] as URLLoader.Listener; // "ls.dele(loader);" may be remove this delegate, it's incorrect. so, romve it first befor dele() call. loader.listeners.RemoveAt(0); // user do not deal with error. then throw this error if (loader.state == URLLoaderState.error && !ls.errNotify) { throw new Exception("AsynResourceMgr -> distribute() -> url[" + loader.fullUrl + "] load error: " + loader.www.error); } if (null == loader.www.assetBundle && !ls.errNotify) { throw new Exception("AsynResourceMgr -> distribute() -> url[" + loader.fullUrl + "] asset bundle is null"); } // notify to user ls.dele(loader, ls.deleCount); } } }
/************************************/ public virtual void Load(bool isUTF8) { Regex reg = new Regex(@"POST:\[(.+?)\]"); Match m = reg.Match(InternalUrl); if (m.Success) { SetPostBody(reg.Replace(m.Value, "$1")); } InternalRealUrl = getRealUrl(InternalUrl); if (string.IsNullOrEmpty(InternalRealUrl)) { throw new Exception("没有初始化Url设置"); } if (UrlLoader == null) { UrlLoader = new URLLoader(); } string result = string.Empty; if (isUTF8) { result = UrlLoader.RequestByUTF8(InternalRealUrl); } else { result = UrlLoader.RequestByGBK(InternalRealUrl); } if (!string.IsNullOrEmpty(result)) { parseHtmlString(result); } }
// async download from _waitingQueue IEnumerator asynDownload() { URLLoader loader = _waitingQueue[0] as URLLoader; if (loader.state != URLLoaderState.waiting) { throw new ArgumentOutOfRangeException("loader.state", "state must be URLLoaderState.waiting"); } loader.state = URLLoaderState.loading; _waitingQueue.Remove(loader); _downloadList.Add(loader); if (loader.fileVersion == -1) { //nnd, "File Not Found" will return true; loader.www = new WWW(loader.fullUrl); } else { loader.www = new WWW(loader.fullUrl); //loader.www = WWW.LoadFromCacheOrDownload(loader.fullUrl, loader.fileVersion); } yield return(loader.www); bool downagain = false; //may be loader had reomve. so need to check if (loader.state != URLLoaderState.destroyed) { //download error? download once again? if (loader.www.error != null) { downagain = true; } } if (downagain) { //destroy error www loader.www.Dispose(); //copy from up if (loader.fileVersion == -1) { //nnd, "File Not Found" will return true; loader.www = new WWW(loader.fullUrl); } else { loader.www = new WWW(loader.fullUrl); //loader.www = WWW.LoadFromCacheOrDownload(loader.fullUrl, loader.fileVersion); } yield return(loader.www); } //--------------------------- // downloaded or error //may be loader had reomve. so need to check if (loader.state != URLLoaderState.destroyed) { if (loader.state != URLLoaderState.loading) { throw new ArgumentOutOfRangeException("loader.state", "state must be URLLoaderState.loading"); } _downloadList.Remove(loader); if (loader.www.error == null) { loader.state = URLLoaderState.loaded; } else { loader.state = URLLoaderState.error; } //notify user _notifyList.Add(loader); distribute(); //donwload next downloadNextOrNot(); } }
public static void remove_progress(URLLoader that, Action <ProgressEvent> value) { CommonExtensions.RemoveDelegate(that, value, ProgressEvent.PROGRESS); }
public static void remove_securityError(URLLoader that, Action <SecurityErrorEvent> value) { CommonExtensions.RemoveDelegate(that, value, SecurityErrorEvent.SECURITY_ERROR); }
/************************************/ public virtual void Load(bool isUTF8, int bookId = 0) { Regex reg = new Regex(@"POST:\[(.+?)\]"); Match m = reg.Match(InternalUrl); if (m.Success) { SetPostBody(reg.Replace(m.Value, "$1")); } InternalRealUrl = getRealUrl(InternalUrl); if (string.IsNullOrEmpty(InternalRealUrl)) { throw new Exception("没有初始化Url设置"); } if (UrlLoader == null) { UrlLoader = new URLLoader(); } string result = string.Empty; Log.ShowLine("请求:" + InternalRealUrl, ConsoleColor.DarkGray); if (isUTF8) { result = UrlLoader.RequestByUTF8(InternalRealUrl); } else { result = UrlLoader.RequestByGBK(InternalRealUrl); } if (!string.IsNullOrEmpty(result)) { if (PageType == PageTypeEnum.NONE) { PageType = PageFeature.MatchHtml(result); } if (PluginGeneral.DEBUG_MODE) { parseHtmlString(result, bookId); } else { try { parseHtmlString(result, bookId); } catch (Exception exp) { FinalData = null; Log.ShowLine(exp, ConsoleColor.Red); _logger.FatalFormat("访问网页:{0}。出错{1}。返回内容为空", InternalRealUrl, exp.Message); } } } else { FinalData = null; Log.ShowLine(InternalRealUrl + " 错误~!", ConsoleColor.Red); _logger.FatalFormat("访问网页:{0}。出错。返回内容为空", InternalRealUrl); } }
public Task <byte[]> UploadValuesTaskAsync(Uri address, NameValueCollection data) { // X:\jsc.svn\examples\actionscript\Test\TestWorkerUploadValuesTaskAsync\TestWorkerUploadValuesTaskAsync\ApplicationSprite.cs // https://forums.adobe.com/thread/1189679 var xx = new TaskCompletionSource <byte[]>(); // X:\jsc.svn\examples\actionscript\Test\TestUploadValuesTaskAsync\TestUploadValuesTaskAsync\ApplicationSprite.cs var request = new URLRequest(address.ToString()) { method = URLRequestMethod.POST }; // should we use dynamic instead? var x = new DynamicContainer { Subject = new URLVariables() }; foreach (var item in data.AllKeys) { x[item] = data[item]; } // http://stackoverflow.com/questions/12774611/urlrequest-urlloader-auto-converting-post-request-to-get // !!!! request.data = (object)x.Subject; //request.contentType = "" var loader = new URLLoader(); // http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoaderDataFormat.html //loader.dataFormat = URLLoaderDataFormat.Binary; loader.dataFormat = "binary"; // http://stackoverflow.com/questions/7816231/how-to-use-as3-to-load-binary-data-from-web-server loader.complete += args => { // If the dataFormat property is URLLoaderDataFormat.BINARY, the received data is a ByteArray object // containing the raw binary data. // TypeError: Error #1034: Type Coercion failed: cannot convert ScriptCoreLib.Shared.BCLImplementation.System.Net::__DownloadStringCompletedEventArgs@5422ad9 to ScriptCoreLib.Shared.BCLImplementation.System.Net.__UploadValuesCompletedEventArgs. //at ScriptCoreLib.ActionScript.BCLImplementation.System.Net::__WebClient/_UploadValuesAsync_b__7_4ebbe596_06000fb2()[V:\web\ScriptCoreLib\ActionScript\BCLImplementation\System\Net\__WebClient.as:143] //at flash.events::EventDispatcher/dispatchEventFunction() //at flash.events::EventDispatcher/dispatchEvent() //at flash.net::URLLoader/redirectEvent() // TypeError: Error #1034: Type Coercion failed: cannot convert ScriptCoreLib.Shared.BCLImplementation.System.Net::__DownloadStringCompletedEventArgs@53686e9 to ScriptCoreLib.Shared.BCLImplementation.System.Net.__UploadValuesCompletedEventArgs. //throw new Exception( // new { loader.data, loader.dataFormat, t = loader.data.GetType() }.ToString() //); var bytes = (ByteArray)loader.data; var Result = (byte[])bytes.ToArray(); //if (UploadValuesCompleted != null) // UploadValuesCompleted(this, (UploadValuesCompletedEventArgs)(object)e); xx.SetResult(Result); }; loader.ioError += args => { var e = new __UploadValuesCompletedEventArgs { Error = new Exception("ioError") }; //if (UploadValuesCompleted != null) // UploadValuesCompleted(this, (UploadValuesCompletedEventArgs)(object)e); throw e.Error; }; loader.securityError += args => { var e = new __UploadValuesCompletedEventArgs { Error = new Exception( "securityError " + new { args.errorID, args.text } ) }; //if (UploadValuesCompleted != null) // UploadValuesCompleted(this, (UploadValuesCompletedEventArgs)(object)e); throw e.Error; }; loader.load(request); return(xx.Task); }
void autoDelete() { if (!_delayAutoDelete) { return; } // all downloads prevent auto delete is true, or nothing, will continue. bool del = true; foreach (URLLoader loader in _downloadList) { if (loader.preventAutoDelete == false) { del = false; break; } } if (!del) { return; } // all waitingQueue prevent auto delete is true, or nothing, will continue. foreach (URLLoader loader in _waitingQueue) { if (loader.preventAutoDelete == false) { del = false; break; } } if (!del) { return; } // Ensure all event is distribute distribute(); // int count0 = _URLLoaders.Count; string[] keys = new string[_URLLoaders.Keys.Count]; _URLLoaders.Keys.CopyTo(keys, 0); foreach (string key in keys) { URLLoader loader = _URLLoaders[key] as URLLoader; bool prevent = loader.preventAutoDelete; loader.preventAutoDelete = false; // !! if (!loader.autoDelete) { continue; } if (prevent == true) //prevent auto delete { continue; } if (loader.state != URLLoaderState.loaded && loader.state != URLLoaderState.error) { continue; } if (loader.listeners.Count != 0) { continue; } destroyLoader(loader, false, false); } // very important here _delayAutoDelete = false; Debug.Log("AsynResourceMgr.autoDelete call! Loader Num:" + count0.ToString() + " -> " + _URLLoaders.Count.ToString()); }
public static void remove_open(URLLoader that, Action <Event> value) { CommonExtensions.RemoveDelegate(that, value, Event.OPEN); }