public async Task <PartialViewResult> GetNearbyInfo(string country, string zip) { IpController zc = new IpController(); if (country == "" || country == null) { var apiIP = zc.GetIPApiAddress(); country = apiIP.Result.Country; } if (zip == "" || zip == null) { var apiIP = zc.GetIPApiAddress(); zip = apiIP.Result.Zip; } NearbyInfo nearInfo = null; using (var client = new HttpClient()) { var json2 = await client.GetStringAsync("http://api.zippopotam.us/nearby/" + country + "/" + zip); nearInfo = JsonSerializer.Deserialize <NearbyInfo>(json2, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); } return(PartialView("GetNearbyInfo_Partial", nearInfo)); }
public async Task <ZipInfo> GetZipDetail(string country, string zip) { IpController zc = new IpController(); if (country == "" || country == null) { var apiIP = zc.GetIPApiAddress(); country = apiIP.Result.Country; } if (zip == "" || zip == null) { var apiIP = zc.GetIPApiAddress(); zip = apiIP.Result.Zip; } ZipInfo zipInfo = null; using (var client = new HttpClient()) { var json1 = await client.GetStringAsync("http://api.zippopotam.us/" + country + "/" + zip);; zipInfo = JsonSerializer.Deserialize <ZipInfo>(json1, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); } return(zipInfo); }