asp.net C# 直接读取或访问其它网站的URL示例

asp.net C# 直接读取或访问其它网站的URL示例

基于抓取网站的思路

些示例可代替部分WebService,返回简单的字符串

#region 获取URL的返回结果 //访问但不返回结果 public void AccessURL(string strUrl) { try { WebRequest request = WebRequest.Create(strUrl); WebResponse response = request.GetResponse(); //StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312")); //reader.ReadToEnd(); //reader.Close(); //reader.Dispose(); response.Close(); } catch { } } //返回URL结果 public string GetURLResult(string strUrl) { string strMsg = ""; try { WebRequest request = WebRequest.Create(strUrl); WebResponse response = request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312")); strMsg = reader.ReadToEnd(); reader.Close(); reader.Dispose(); response.Close(); } catch { } return strMsg; } #endregion

你可能感兴趣的:(.net)