【问题标题】:Error 407 (Proxy Authentication Request) on Web Request via Geocoding API通过地理编码 API 的 Web 请求出现错误 407(代理身份验证请求)
【发布时间】:2021-12-05 17:12:22
【问题描述】:

我正在编写一段代码,它将接收用户输入的地址,并返回纬度/经度值以供以后使用。为此,我使用了地理编码 API。我所拥有的是:

try
{
    IGeocoder geo = new GoogleGeocoder() { };
    Address[] addresses = geo.Geocode(address.Text).ToArray();
    foreach (Address adr in addresses)
    {
        // just testing it out
        MessageBox.Show(adr.Coordinates.ToString());
    }
}
catch (Exception ex)
{
    // error treating
}

address 是一个文本框,用户可以在其中输入地址。但是,当我运行它时,我得到了 407 错误。

我已经阅读了很多问题并尝试了他们的解决方案(例如 this onethis one),但都没有奏效。

关于我缺少什么的任何想法?

【问题讨论】:

  • 看起来是代理渗透的问题。没有来自您的机器(您的防火墙)的请求,或者代理没有到达那里(代理的防火墙),或者您的连接信息(地址、端口、凭据)错误。如果你真的添加了 App.config 以及工作凭据、正确的本地地址、它的端口,那么防火墙会告诉你什么?
  • 你在哪里设置网址?您是否与休息客户一起尝试过?你得到了什么?

标签: c# wpf httpwebrequest


【解决方案1】:

由于它引发了关于代理的错误,您可以尝试将您的代理详细信息设置为GoogleGeocoder class

GoogleGeocoder geocoder = new GoogleGeocoder
{
    Proxy = new WebProxy
    {
        Address = new Uri("proxy url"),
        Credentials = new NetworkCredential("username", "password")
    }
};

【讨论】:

  • 您好 cdev,感谢您帮助我。但是,它现在抛出另一个错误:“no such host is known”。
  • 那是由于DNS失败,上面的调用会尝试通过代理连接google apis。然后代理或您的网络无法解析主机。我建议你先尝试使用邮递员的谷歌 API。首先找出网络问题。然后相应地调整代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-09
  • 1970-01-01
相关资源
最近更新 更多