Veltar
Veltar

Reputation: 741

get xml from webservice

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.

Upvotes: 1

Views: 3605

Answers (2)

ZombieSheep
ZombieSheep

Reputation: 29953

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.

Upvotes: 1

SliverNinja - MSFT
SliverNinja - MSFT

Reputation: 31641

You can use John Saunders approach and call WebClient.DownloadString

Upvotes: 2

Related Questions