/// <summary>创建客户端会话</summary> /// <param name="uri"></param> /// <returns></returns> protected virtual HttpWebRequest Create(String uri) { var req = WebRequest.Create(uri) as HttpWebRequest; req.UserAgent = UserAgent; if (AutomaticDecompression != DecompressionMethods.None) { req.AutomaticDecompression = AutomaticDecompression; } if (!Accept.IsNullOrEmpty()) { req.Accept = Accept; } if (!AcceptLanguage.IsNullOrEmpty()) { req.Headers[HttpRequestHeader.AcceptLanguage + ""] = AcceptLanguage; } if (!Referer.IsNullOrEmpty()) { req.Referer = Referer; } return(req); }
private IHttpWebRequest PrepareRequestObject(Uri url, string method, string contentType, int timeoutMilliseconds) { IHttpWebRequest req = _reqFactory.GetWebRequest(url); req.Method = method; req.ContentType = contentType; // "application/x-www-form-urlencoded"; req.UserAgent = UserAgent; req.Accept = Accept ?? "*/*"; req.Timeout = timeoutMilliseconds; req.AllowAutoRedirect = false; if (UseGZip) { req.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip; } req.CookieContainer = Cookies; if (_proxy != null) { req.Proxy = _proxy; } if (Referer != null) { req.Referer = Referer.ToString(); } return(req); }
/// <summary>创建客户端会话</summary> /// <returns></returns> public virtual HttpClientX EnsureCreate() { var http = _client; if (http == null) { var p = Proxy; if (p == null && !ProxyAddress.IsNullOrEmpty()) { Proxy = p = new WebProxy(ProxyAddress); } if (p == null) { http = new HttpClientX(); } else { http = new HttpClientX(new HttpClientHandler { Proxy = p }); } _client = http; Request = http.DefaultRequestHeaders; http.Timeout = new TimeSpan(0, 0, 0, 0, Timeout); } var req = http.DefaultRequestHeaders; if (!UserAgent.IsNullOrEmpty()) { req.UserAgent.ParseAdd(UserAgent); } if (!Accept.IsNullOrEmpty()) { req.Accept.ParseAdd(Accept); } if (!AcceptLanguage.IsNullOrEmpty()) { req.AcceptLanguage.ParseAdd(AcceptLanguage); } if (AutomaticDecompression != DecompressionMethods.None) { req.AcceptEncoding.ParseAdd("gzip, deflate"); } if (!Referer.IsNullOrEmpty()) { req.Referrer = new Uri(Referer); } GetCookie(); return(http); }
public override int GetHashCode() { int hash = 1; if (RequestMethod.Length != 0) { hash ^= RequestMethod.GetHashCode(); } if (RequestUrl.Length != 0) { hash ^= RequestUrl.GetHashCode(); } if (RequestSize != 0L) { hash ^= RequestSize.GetHashCode(); } if (Status != 0) { hash ^= Status.GetHashCode(); } if (ResponseSize != 0L) { hash ^= ResponseSize.GetHashCode(); } if (UserAgent.Length != 0) { hash ^= UserAgent.GetHashCode(); } if (RemoteIp.Length != 0) { hash ^= RemoteIp.GetHashCode(); } if (Referer.Length != 0) { hash ^= Referer.GetHashCode(); } if (CacheHit != false) { hash ^= CacheHit.GetHashCode(); } if (ValidatedWithOriginServer != false) { hash ^= ValidatedWithOriginServer.GetHashCode(); } return(hash); }
protected override System.Net.WebRequest GetWebRequest(System.Uri address) { _Url = address; var basereq = base.GetWebRequest(address); System.Net.HttpWebRequest req = basereq as System.Net.HttpWebRequest; if (req != null) { if (ContentType != null) { req.ContentType = ContentType; } req.AllowAutoRedirect = false; req.CookieContainer = Cookies; req.AutomaticDecompression = System.Net.DecompressionMethods.GZip | DecompressionMethods.Deflate; if (Timeout > 0) { req.Timeout = Timeout * 1000; } if (!Referer.IsNullOrEmpty()) { req.Referer = Referer; } if (!UserAgent.IsNullOrEmpty()) { req.UserAgent = UserAgent; } if (IfModifiedSince != null) { req.IfModifiedSince = IfModifiedSince.Value; } req.KeepAlive = KeepAlive; req.Accept = Headers[HttpRequestHeader.Accept].NotEmpty(Headers["accept"], req.Accept); if (OnGetWebRequest != null) { OnGetWebRequest(address, req); } } return(basereq); }
/// <summary>创建客户端会话</summary> /// <returns></returns> protected virtual HttpClientX Create() { var http = _client; if (http == null) { http = _client = new HttpClientX(); Request = http.DefaultRequestHeaders; http.Timeout = new TimeSpan(0, 0, 0, 0, Timeout); } var req = http.DefaultRequestHeaders; if (!UserAgent.IsNullOrEmpty()) { req.UserAgent.ParseAdd(UserAgent); } if (!Accept.IsNullOrEmpty()) { req.Accept.ParseAdd(Accept); } if (!AcceptLanguage.IsNullOrEmpty()) { req.AcceptLanguage.ParseAdd(AcceptLanguage); } if (AutomaticDecompression != DecompressionMethods.None) { req.AcceptEncoding.ParseAdd("gzip, deflate"); } if (!Referer.IsNullOrEmpty()) { req.Referrer = new Uri(Referer); } GetCookie(); return(http); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { switch (Sql.Sql) { case SqlType.PostgreSql: break; case SqlType.SqLite: //弹幕表 modelBuilder.Entity <DanmuTable>().Property(e => e.Ip).HasColumnType("TEXT") .HasConversion(v => v.ToString(), v => IPAddress.Parse(v)); modelBuilder.Entity <DanmuTable>().Property(e => e.Data).HasColumnType("TEXT") .HasConversion(v => v.ToJson(), v => (BaseDanmuData)v); //视频表 modelBuilder.Entity <VideoTable>().Property(e => e.Referer).HasColumnType("TEXT") .HasConversion(v => v.ToJson(), v => Referer.FromJson(v)); break; } modelBuilder.Entity <DanmuTable>().Property(p => p.IsDelete).HasDefaultValue(false); modelBuilder.Entity <DanmuTable>().HasIndex(d => new { d.Vid, d.IsDelete }); }
/// <summary>创建客户端会话</summary> /// <returns></returns> public virtual HttpClient EnsureCreate() { var http = _client; if (http == null) { var p = Proxy; if (p == null && !ProxyAddress.IsNullOrEmpty()) { Proxy = p = new WebProxy(ProxyAddress); } var handler = new HttpClientHandler(); if (p != null) { handler.UseProxy = true; handler.Proxy = p; } else { handler.UseProxy = false; handler.Proxy = null; } if (AutomaticDecompression != DecompressionMethods.None) { handler.AutomaticDecompression = AutomaticDecompression; } http = new HttpClient(handler); _client = http; Request = http.DefaultRequestHeaders; http.Timeout = new TimeSpan(0, 0, 0, 0, Timeout); } var req = http.DefaultRequestHeaders; if (!UserAgent.IsNullOrEmpty()) { req.UserAgent.ParseAdd(UserAgent); } if (!Accept.IsNullOrEmpty()) { req.Accept.ParseAdd(Accept); } if (!AcceptLanguage.IsNullOrEmpty()) { req.AcceptLanguage.ParseAdd(AcceptLanguage); } if (AutomaticDecompression != DecompressionMethods.None) { req.AcceptEncoding.ParseAdd("gzip, deflate"); } if (!Referer.IsNullOrEmpty()) { req.Referrer = new Uri(Referer); } if (KeepAlive) { req.Connection.ParseAdd("keep-alive"); } GetCookie(http); return(http); }
/// <summary> /// 初始化请求 /// </summary> /// <param name="context"></param> internal void InitializeWebRequest([NotNull] HttpContext context) { var request = context.WebRequest; if (!Accept.IsNullOrEmpty()) { request.Accept = Accept; } if (!UserAgent.IsNullOrEmpty()) { request.UserAgent = UserAgent; } if (!AcceptEncoding.IsNullOrEmpty()) { request.Headers.Add(HttpRequestHeader.AcceptEncoding, AcceptEncoding); } request.ServicePoint.Expect100Continue = false; request.KeepAlive = KeepAlive; request.ServicePoint.UseNagleAlgorithm = UseNagleAlgorithm; request.AllowWriteStreamBuffering = AllowWriteStreamBuffering; Authorization?.SetRequest(context.WebRequest, context); if (Range != null) { var range = Range.Value; #if NET_GT_4 if (range.Value.HasValue) { request.AddRange(range.Key, range.Value.Value); } else { request.AddRange(range.Key); } #else if (range.Value.HasValue) { request.AddRange(range.Key, range.Value.Value); } else { request.AddRange(range.Key); } #endif } if (AppendAjaxHeader) { request.Headers.Add("X-Requested-With", "XMLHttpRequest"); } request.KeepAlive = KeepAlive; if (Timeout.HasValue) { request.Timeout = Timeout.Value; } if (ReadWriteTimeout.HasValue) { request.ReadWriteTimeout = ReadWriteTimeout.Value; } if (!TransferEncoding.IsNullOrEmpty()) { request.TransferEncoding = TransferEncoding; request.SendChunked = true; } #if NET_GT_4 if (!string.IsNullOrEmpty(Host)) { request.Host = Host; } #endif request.AllowAutoRedirect = AllowAutoRedirect; request.AutomaticDecompression = DecompressionMethods.None; #pragma warning disable 618 if (ReferUri != null) { request.Referer = ReferUri.OriginalString; } #pragma warning restore 618 if (!Referer.IsNullOrEmpty()) { request.Referer = Referer; } if (HttpRequestCacheLevel != null) { request.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.Value); } else if (HttpCacheAgeControl != null) { request.CachePolicy = new HttpRequestCachePolicy(HttpCacheAgeControl.Value, MaxAge ?? TimeSpan.Zero, AgeOrFreshOrStale ?? TimeSpan.Zero, SyncTime ?? DateTime.Now); } if (IfModifiedSince != null) { request.IfModifiedSince = IfModifiedSince.Value; } //copy headers if (Headers != null) { foreach (var header in Headers.AllKeys) { request.Headers[header] = Headers[header]; } } if (_proxySet) { request.Proxy = _webProxy; } request.PreAuthenticate = PreAuthenticate; //初始化兼容参数 if (request.Proxy != null) { if (Context.Client.Setting.ForceStreamBufferWithProxy) { //如果有代理,则默认允许流缓冲。如果不允许,则很可能会导致代理身份验证失败。 request.AllowWriteStreamBuffering = true; } if (request.Proxy is WebProxy) { var proxy = request.Proxy as WebProxy; if (!proxy.UseDefaultCredentials && proxy.Credentials is NetworkCredential && request.Headers["Proxy-Authorization"].IsNullOrEmpty()) { var cred = proxy.Credentials as NetworkCredential; request.Headers.Set(HttpRequestHeader.ProxyAuthorization, "Basic " + Convert.ToBase64String(Encoding.GetBytes(cred.UserName + ":" + cred.Password))); } } } //如果设置了证书,则添加 if (X509Certificates?.Length > 0) { request.ClientCertificates.AddRange(X509Certificates); } OnPostInitRequest(new PostInitRequestEventArgs(request, context, context.Client)); }
public override int GetHashCode() { int hash = 1; if (RequestMethod.Length != 0) { hash ^= RequestMethod.GetHashCode(); } if (RequestUrl.Length != 0) { hash ^= RequestUrl.GetHashCode(); } if (RequestSize != 0L) { hash ^= RequestSize.GetHashCode(); } if (Status != 0) { hash ^= Status.GetHashCode(); } if (ResponseSize != 0L) { hash ^= ResponseSize.GetHashCode(); } if (UserAgent.Length != 0) { hash ^= UserAgent.GetHashCode(); } if (RemoteIp.Length != 0) { hash ^= RemoteIp.GetHashCode(); } if (ServerIp.Length != 0) { hash ^= ServerIp.GetHashCode(); } if (Referer.Length != 0) { hash ^= Referer.GetHashCode(); } if (latency_ != null) { hash ^= Latency.GetHashCode(); } if (CacheLookup != false) { hash ^= CacheLookup.GetHashCode(); } if (CacheHit != false) { hash ^= CacheHit.GetHashCode(); } if (CacheValidatedWithOriginServer != false) { hash ^= CacheValidatedWithOriginServer.GetHashCode(); } if (CacheFillBytes != 0L) { hash ^= CacheFillBytes.GetHashCode(); } if (Protocol.Length != 0) { hash ^= Protocol.GetHashCode(); } return(hash); }
public override void _Process(float delta) { float spawnZoneExtends = 640; Vector2 globalPosition = ((Node2D)Referer).GlobalPosition; Rect2 spawnZone = new Rect2(globalPosition, spawnZoneExtends, spawnZoneExtends); foreach (Node n in GetTree().GetNodesInGroup("EndPositions")) { Position2D pos = (Position2D)n; LavaBlock lb = (LavaBlock)pos.GetParent(); if (spawnZone.HasPoint(pos.GlobalPosition) && !lb.loadedNext) { PackedScene nextToSpawn = GD.Load <PackedScene>("tests/thibault/lava_blocks/" + lb.nexts[(int)(GD.Randi() % lb.nexts.Count)] + ".tscn"); LavaBlock nextBlock = (LavaBlock)nextToSpawn.Instance(); nextBlock.camera = lb.camera; nextBlock.GlobalPosition = pos.GlobalPosition; Referer.GetParent().AddChild(nextBlock); lb.loadedNext = true; Array <LavaSurfaceBurn> nextLavas = new Array <LavaSurfaceBurn>(); foreach (Node n2 in GetTree().GetNodesInGroup("LavaBurn")) { LavaSurfaceBurn l = (LavaSurfaceBurn)n2; if (l.GetParent() == nextBlock) { nextLavas.Add(l); } } for (int i = 0; i < nextLavas.Count; i++) { if (i != 0 || lavaSurface.isInterrupted) { surfaces.Add(lavaSurface); lavaSurface = (LavaSurfaceBurn)lavaPacked.Instance(); GetTree().CurrentScene.AddChild(lavaSurface); } LavaSurfaceBurn nextLava = nextLavas[i]; Vector2 offset = nextLava.GlobalPosition; foreach (Vector2 p in nextLava.Points) { lavaSurface.AddPoint(p + offset); } lavaSurface.isInterrupted = nextLava.isInterrupted; nextLava.QueueFree(); } } else if ((pos.GlobalPosition.x - globalPosition.x) < -spawnZoneExtends) { lb.QueueFree(); while (surfaces.Count > 0) { LavaSurfaceBurn ls = surfaces[0]; float maxX = 0; for (int i = 0; i < ls.Points.Length; i++) { maxX = Mathf.Max(maxX, ls.GetPointPosition(i).x); } if (maxX - globalPosition.x < -spawnZoneExtends) { surfaces.RemoveAt(0); ls.QueueFree(); } else { break; } } } } }
public void Run(ref CookieContainer cookies) { _request = (HttpWebRequest)WebRequest.Create(Address); _request.Headers.Add("DNT", "1"); _request.Method = "Get"; _request.Accept = Accept; _request.Host = Host; if (TurnOffProxy) { _request.Proxy = null; } else { _request.Proxy = Proxy; } if (UseUnsafeHeaderParsing) { var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var settings = (SettingsSection)config.GetSection("system.net/settings"); settings.HttpWebRequest.UseUnsafeHeaderParsing = true; config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("system.net/settings"); } if (TimeOut > 0) { _request.Timeout = TimeOut; _request.ReadWriteTimeout = TimeOut; } else { _request.Timeout = 35000; _request.ReadWriteTimeout = 35000; } if (NoCachePolicy == false) { var noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore); _request.CachePolicy = noCachePolicy; } foreach (KeyValuePair <string, string> keyValuePair in Headers) { _request.Headers.Add(keyValuePair.Key, keyValuePair.Value); } if (UserAgent == null) { _request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko"; } else { _request.UserAgent = UserAgent; } if (AllowAutoRedirect != null) { _request.AllowAutoRedirect = (bool)AllowAutoRedirect; } if (KeepAlive != null) { _request.KeepAlive = (bool)KeepAlive; } if (Expect100Continue != null) { _request.ServicePoint.Expect100Continue = (bool)Expect100Continue; } if (!Referer.IsEmpty()) { _request.Referer = Referer; } _request.CookieContainer = cookies; try { HttpWebResponse response = (HttpWebResponse)_request.GetResponse(); if ((response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Moved || response.StatusCode == HttpStatusCode.Redirect) && response.ContentType.StartsWith("image", StringComparison.OrdinalIgnoreCase)) { // if the remote file was found, download oit using (Stream inputStream = response.GetResponseStream()) { byte[] buffer = new byte[64000]; int bytesRead; bytesRead = inputStream.Read(buffer, 0, buffer.Length); Response = Convert.ToBase64String(buffer, 0, bytesRead); } } else { var stream = response.GetResponseStream(); if (stream != null) { Response = new StreamReader(stream).ReadToEnd(); } ResponseHeaders = response.Headers; RequestHeaders = _request.Headers; } response.Close(); } catch (WebException ex) { using (var stream = ex.Response.GetResponseStream()) using (var reader = new StreamReader(stream)) { Response = reader.ReadToEnd(); } } catch (Exception ex) { } }
public string GetClientIP(Dictionary <String, String> requestDir) { string HeaderClientIP = ""; string UriClientIP = ""; string clientIP = ""; string SkyserverWSPath = (new Uri(ConfigurationManager.AppSettings["skyServerWS"])).LocalPath; string SkyserverUrlHost = (new Uri(ConfigurationManager.AppSettings["skyServerUrl"])).Host; string RefererHost = ""; string Referer = HttpContext.Current.Request.Headers["Referer"]; if (!string.IsNullOrEmpty(HttpContext.Current.Request.Headers[ConfigurationManager.AppSettings["RefererHeaderName"]])) { Referer = new Uri(HttpContext.Current.Request.Headers[ConfigurationManager.AppSettings["RefererHeaderName"]]).ToString(); } if (!string.IsNullOrEmpty(Referer)) { RefererHost = (new Uri(Referer)).Host; } if (!string.IsNullOrEmpty(HttpContext.Current.Request.Headers[ConfigurationManager.AppSettings["RefererHeaderName"]])) { RefererHost = (new Uri(HttpContext.Current.Request.Headers[ConfigurationManager.AppSettings["RefererHeaderName"]])).Host; } try { HeaderClientIP = HttpContext.Current.Request.Headers[ConfigurationManager.AppSettings["IpHeaderName"]]; UriClientIP = HttpContext.Current.Request.Params["clientIP"]; if (RefererHost == SkyserverUrlHost && !Referer.ToLower().Contains(SkyserverWSPath.ToLower())) { IsDirectUserConnection = false;// request coming from skyserver } else { IsDirectUserConnection = true; } if ((!String.IsNullOrEmpty(HeaderClientIP) || !String.IsNullOrEmpty(UriClientIP)) && !IsDirectUserConnection) { if (!String.IsNullOrEmpty(HeaderClientIP)) { clientIP = HeaderClientIP; } else { clientIP = UriClientIP; } } else { clientIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; string[] addresses = new string[] { }; try { addresses = clientIP.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); } catch { } if (addresses.Length > 0) { clientIP = addresses[0]; } if (String.IsNullOrEmpty(clientIP)) { clientIP = HttpContext.Current.Request.UserHostAddress; } } } catch { } if (string.IsNullOrEmpty(clientIP)) { clientIP = "unknown"; } //return (clientIP).Substring(0, Math.Min(clientIP.Length, 50)); return(clientIP); }