我会做这样的事情:
try { WebClient wc = new WebClient(); wc.Headers.Add();//ADD ALL YOUR HEADERS IF YOU NEED var xml = wc.DownloadString(string.Format("http://smart-ip.net/geoip-xml/{0}", txtIP.Text)); XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); var name = doc.DocumentElement.SelectSingleNode("//countryName").Value; txtIPresults.Text = name } catch (Exception myException) { throw new Exception("Error Occurred:", myException); }
我不确定它是否比HTTP REQUEST / RESPONSE具有更高的性能,但代码非常小且易于维护。