日期:2014-05-18 浏览次数:20618 次
public string GetNetwork2() { // string url = "http://whois.pconline.com.cn/ip.jsp"; string url = "http://counter.sina.com.cn/ip"; string ip = SitePower.Common.StringHelper.GetClientIP(); string query = "ip=" + ip; url += "?ip=" + ip; string text = GetResponseText(url, query); int startstr=text.IndexOf("Array("); int endstr=text.IndexOf("\");"); string[] textarray = text.Substring(startstr, (endstr - startstr)).Split(','); return textarray[3].Replace("\"",string.Empty).Trim(); } /// <summary> /// 获取响应的数据流。 /// </summary> /// <returns></returns> public Stream GetResponseStream(string API_URL, string query) { var data = Encoding.UTF8.GetBytes(query); var request = (HttpWebRequest)WebRequest.Create(API_URL); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; using (var stream = request.GetRequestStream()) stream.Write(data, 0, data.Length); return request.GetResponse().GetResponseStream(); } /// <summary> /// 获取响应的文本。 /// </summary> /// <returns></returns> public string GetResponseText(string API_URL, string query) { var text = string.Empty; using (var reader = new StreamReader(this.GetResponseStream(API_URL, query), Encoding.Default)) text = reader.ReadToEnd(); return text; }