我正在尝试使用 Yahoo 的 PlaceFinder API 来获取邮政编码的经度和纬度。在我的本地机器上一切正常,但是当我将它上传到我的生产服务器时,我收到来自 Yahoo 的连接被拒绝错误。我在下面复制了我的代码:
Dictionary<string, decimal> GetYahooGeoCode(string postcode)
{
string url = "http://where.yahooapis.com/geocode?flags=J&appid=[My_App_ID]&location=";
decimal latitude = 0;
decimal longitude = 0;
try
{
dynamic yahooResults = new Uri(url + postcode).GetDynamicJsonObject();
foreach (var result in yahooResults.ResultSet.Results)
{
latitude = (decimal)result.latitude;
longitude = (decimal)result.longitude;
}
Dictionary<string, decimal> geoCode = new Dictionary<string, decimal>();
geoCode.Add("latitude", latitude);
geoCode.Add("longitude", longitude);
return geoCode;
}
catch (Exception ex)
{
Log4NetLogger logger = new Log4NetLogger();
logger.Error(ex);
return null;
}
}
我得到的错误是:无法建立连接,因为目标机器主动拒绝了它。有人对此有任何想法吗?我做了很多搜索,似乎找不到有关此问题的任何信息。我不知道这是否有任何区别,但我的生产服务器是专用的云服务器。任何帮助,将不胜感激。