C # How to Use youdao IP address to query interface instances
This example describes how to use the IP address query interface in C. Share it with you for your reference. The specific implementation method is as follows:
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# Region read the IP address of the http://www.yodao.com Interface /// <Summary> // Read the IP address of the http://www.yodao.com Interface /// </Summary> Public static string GetstringIpAddress (string strIP) // the strIP is an IP address. { String sURL = "http://www.youdao.com/smartresult-xml/search.s? Type = ip & q = "+ strIP + ""; // Youdao URL String stringIpAddress = ""; Using (XmlReader read = XmlReader. Create (sURL )) // Obtain the content of the xml format file returned by youdao { While (read. Read ()) { Switch (read. NodeType) { Case XmlNodeType. Text: // retrieve the Text content of an xml file If (string. Format ("{0}", read. Value). ToString (). Trim ()! = StrIP) // The content of the xml format file returned by youdao is an IP address, // The other is an IP address. If it is not an IP address, it is an IP address. { StringIpAddress = string. Format ("{0}", read. Value). ToString (). Trim (); // assign a Value } Break; // Other } } } Return stringIpAddress; } |
Returned xml data format:
?
| 1 2 3 4 5 6 7 |
<? Xml version = "1.0" encoding = "gbk"?> <Smartresult> <Product type = "ip"> <Ip> 60.223.233.226 </ip> <Location> Shanxi Shuozhou Netcom </location> </Product> </Smartresult> |
I hope this article will help you with C # programming.