2011-12-15 79 views
1

我需要調用Web服務XML,返回該XML得到web服務

<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> 

這是網址:

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"; 

我如何能趕上,在ASP?我嘗試了一個Web服務,但無法弄清楚。

+0

XML是否通過輸入參數或URI路徑進行更改? – SliverNinja 2011-12-15 16:29:37

回答

1

你只需要做這樣的事情......那麼

WebClient client = new WebClient(); 
string result = client.DownloadString(api_url); 

字符串result應持有從URL中下載的內容。