I need to call a web service, that returns this xml
<Response>
<statusCode>OK</statusCode>
<statusMessage/>
<ipAddress>127.0.0.1</ipAddress>
<countryCode>-</countryCode>
<countryName>-</countryName>
<regionName>-</regionName>
<cityName>-</cityName>
<zipCode>-</zipCode>
<latitude>0</latitude>
<longitude>0</longitude>
<timeZone>-</timeZone>
</Response>
This is the URL:
String userIp = HttpContext.Current.Request.UserHostAddress;
// api key
String api_key = "01cce0db52b4eafaf8eac3f5b560fa4b5bf20f1410763224557d05eb949a2b3c";
// service url
String api_url = "http://api.ipinfodb.com/v3/ip-city/?key=" +api_key +"&ip="+ userIp +"&format=xml";
How can I catch that in asp? I tried with a web service but can't figure it out.
您可以使用John Saunders方法并调用WebClient.DownloadString
You just need to do something like this...
WebClient client = new WebClient();
string result = client.DownloadString(api_url);
The string result
should then hold the downloaded content from the url.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.