墨香年少 32 发布于 2020年12月25日 private string getHTML(string url) { if (url.Substring(0, 4) != "http") { return "error"; } HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; try { HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode.ToString() != "OK") { return "error"; } if (response.StatusCode == HttpStatusCode.NotFound) return "error"; if (response.StatusCode == HttpStatusCode.InternalServerError) return "error"; if (response.StatusCode == HttpStatusCode.BadGateway) return "error"; Stream ResponseStream = response.GetResponseStream(); StreamReader sr = new StreamReader(ResponseStream, Encoding.UTF8); string html = sr.ReadToEnd(); sr.Close(); ResponseStream.Close(); return html; } catch (Exception e) { return "error"; } return "error"; } 目之所及,皆是回忆,心之所想,皆是过往 分享这篇帖子 链接帖子 分享到其他站点