62,046
社区成员
发帖
与我相关
我的任务
分享
string strIP = this.txtIP.Text.Trim();
string strAction = "2";
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "ip=" + strIP;
postData += "&action=" + strAction;
byte[] data = encoding.GetBytes(postData);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://www.ip138.com/ips.asp");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream myStream = myRequest.GetRequestStream();
myStream.Write(data, 0, data.Length);
myStream.Close();
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default);
string content = reader.ReadToEnd();
string con = content.Substring(content.IndexOf("本站主数据") + 6, content.IndexOf("</li><li>参考数据一") - content.IndexOf("本站主数据") - 1);
this.lblViewIP.Text = con;