欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#使用有道ip地址查詢接口方法實(shí)例詳解

 更新時(shí)間:2015年05月25日 10:33:05   作者:陌香  
這篇文章主要介紹了C#使用有道ip地址查詢接口方法,實(shí)例分析了有道IP地址查詢接口的使用方法與數(shù)據(jù)返回格式,需要的朋友可以參考下

本文實(shí)例講述了C#使用有道ip地址查詢接口方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

#region 讀取http://www.yodao.com接口IP地址
/// <summary>
/// 讀取http://www.yodao.com接口IP地址
/// </summary>
public static string GetstringIpAddress(string strIP)//strIP為IP
{
 string sURL = "http://www.youdao.com/smartresult-xml/search.s?type=ip&q="+strIP+"";
 //youdao的URL
 string stringIpAddress = "";
 using (XmlReader read = XmlReader.Create(sURL))
 //獲取youdao返回的xml格式文件內(nèi)容
 {
  while (read.Read())
  {
   switch (read.NodeType)
   {
    case XmlNodeType.Text://取xml格式文件當(dāng)中的文本內(nèi)容
     if (string.Format("{0}", read.Value).ToString().Trim() != strIP)
     //youdao返回的xml格式文件內(nèi)容一個(gè)是IP,
     //另一個(gè)是IP地址,如果不是IP那么就是IP地址
     {
      stringIpAddress=string.Format("{0}", read.Value).ToString().Trim();//賦值
     }
     break;
    //other
   }
  }
 }
 return stringIpAddress;
}

返回的xml數(shù)據(jù)格式:

<?xml version="1.0" encoding="gbk" ?> 
<smartresult>
<product type="ip">
<ip>60.223.233.226</ip> 
<location>山西省朔州市 網(wǎng)通</location> 
</product>
</smartresult>

希望本文所述對大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論