获取客户端ip 信息

本机IP: 14.111.63.126重庆市重庆市 电信

//地址
string url="http://2019.ip138.com/ic.asp";
HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create(url);
                hwr.Accept = "text/html, application/xhtml+xml, */*";
                hwr.ContentType = "application/x-www-form-urlencoded";
                hwr.Method = "POST";
                hwr.KeepAlive = true;
                hwr.ReadWriteTimeout = 3000;
                byte[] data = Encoding.GetEncoding("gb2312").GetBytes(postPar.ToString());
                using (Stream stream = hwr.GetRequestStream())
                {
                    stream.Write(data, 0, data.Length);
                    stream.Close();
                }
                Stream stre = hwr.GetResponse().GetResponseStream();
                StreamReader sr = new StreamReader(stre);//创建一个stream读取流
                string msgs = sr.ReadToEnd();
                sr.Close();

猜你喜欢

转载自blog.csdn.net/qq_36664772/article/details/88948380