var geocoder = new Geocoding.Google.GoogleGeocoder(apiKey)
{
    Proxy = new System.Net.WebProxy("http://proxy.example:8080")
    {
        Credentials = new System.Net.NetworkCredential(
            proxyUser, proxyPassword)
    }
};

使用应用程序的 API 密钥和中间账户,然后通过这个已配置的地理编码器调用 GeocodeAsync 或 ReverseGeocodeAsync。对于不需要身份验证的中间服务器,请省略 Credentials。在这种情况下,当允许通过公共中间服务器进行公共地理编码请求时,HTTP 代理列表 会提供候选。

Geocoding.NET 的请求路径会创建一个 HttpClientHandler,并为其分配公共的 IWebProxy 属性。在别处配置的另一个 HttpClient 不会替换这条路径。

请将中间服务器返回的 407 与 Google 对无效密钥或请求被拒的响应区分开。对于集成身份验证,请使用适合该代理的 Windows 标识或域,而不要用 Maps 密钥代替代理密码。

相关文章