public static void LoadDataFromUrl(string url) { Console.WriteLine($"正在加载敏感词:{url}"); var oldcount = funNLP_data_sensitive.Count; using (var hr = new TcpClientHttpRequest()) { hr.Action = url; hr.Send(); LoadDataFromText(hr.Response.Xml); } }
public HttpResponse(TcpClientHttpRequest ie, byte[] headBytes) { _action = ie.Action; _method = ie.Method; _charset = ie.Charset; Encoding encode = Encoding.GetEncoding(_charset); string head = encode.GetString(headBytes); _head = head = head.Trim(); int idx = head.IndexOf(' '); if (idx != -1) { head = head.Substring(idx + 1); } idx = head.IndexOf(' '); if (idx != -1) { _statusCode = (HttpStatusCode)int.Parse(head.Remove(idx)); head = head.Substring(idx + 1); } idx = head.IndexOf("\r\n"); if (idx != -1) { head = head.Substring(idx + 2); } string[] heads = head.Split(new string[] { "\r\n" }, StringSplitOptions.None); foreach (string h in heads) { string[] nv = h.Split(new char[] { ':' }, 2); if (nv.Length == 2) { string n = nv[0].Trim(); string v = nv[1].Trim(); if (v.EndsWith("; Secure")) { v = v.Replace("; Secure", ""); } if (v.EndsWith("; version=1")) { v = v.Replace("; version=1", ""); } switch (n.ToLower()) { case "set-cookie": if (ie.CookieContainer != null) { Uri addr = Address; string[] v2d = Regex.Split(v, @"\bdomain=", RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture); if (v2d.Length > 1) { string domain = v2d[1]; idx = domain.IndexOf(";"); if (idx != -1) { domain = domain.Remove(idx); } while (domain.StartsWith(".")) { domain = domain.Substring(1); } domain = "http://" + domain + "/"; if (Uri.IsWellFormedUriString(domain, UriKind.Absolute)) { Uri du = new Uri(domain); if (string.Compare(addr.Authority, du.Authority, true) != 0) { addr = du; } } } lock (ie._cookieContainer_lock) { ie.CookieContainer.SetCookies(addr, v); } } break; case "content-length": if (!int.TryParse(v, out _contentLength)) { _contentLength = -1; } break; case "content-type": idx = v.IndexOf("charset=", StringComparison.CurrentCultureIgnoreCase); if (idx != -1) { string charset = v.Substring(idx + 8); idx = charset.IndexOf(";"); if (idx != -1) { charset = charset.Remove(idx); } if (string.Compare(_charset, charset, true) != 0) { try { Encoding testEncode = Encoding.GetEncoding(charset); _charset = charset; } catch { } } } _contentType = v; break; case "server": _server = v; break; case "content-encoding": _contentEncoding = v; break; default: _headers.Add(n, v); break; } } } }