0

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

私が得ているエラーは次のとおりです。ターゲットマシンがアクティブに拒否したため、接続できませんでした。誰かがこれについて何か考えを持っていますか? 私は多くの検索を行ってきましたが、この問題に関する情報が見つからないようです。これが違いを生むかどうかはわかりませんが、私の運用サーバーは専用のクラウド サーバーです。どんな助けでも大歓迎です。

4

1 に答える 1

0

私はここであなたの問題を解決しようとしています:

web.config を確認します。

<system.net>
    <defaultProxy />
</system.net>

そして私のコード(GetDynamicJsonObject()は応答を解析しませんでした):

        string postcode = "10003";
        string url = String.Format("http://where.yahooapis.com/geocode?state={0}&postal={1}", "NY", postcode);

        Dictionary<string, decimal> geoCode = new Dictionary<string, decimal>();

        System.Xml.Linq.XDocument xDocument = XDocument.Load(url);
        var latlon = (from r in xDocument.Descendants("Result")
                      select new { latitude = r.Element("latitude").Value, longitude = r.Element("longitude").Value }).FirstOrDefault();

        if(null != latlon)
        {
            geoCode.Add("latitude", Convert.ToDecimal(latlon.latitude));
            geoCode.Add("longitude", Convert.ToDecimal(latlon.longitude));
        }

ここで場所検索の yahoo api パラメーターを確認してくださいhttp://developer.yahoo.com/geo/placefinder/guide/requests.html#base-uri

于 2012-03-01T17:15:11.477 に答える