通过地理编码API的Web请求错误407(代理身份验证请求)



我正在编写一段代码,它将接收用户输入的地址,并返回纬度/经度值供以后使用。为此,我使用Geocoding 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错误。

我读了很多问题并尝试了它们的解决方案(比如这个,或者这个),但是没有一个奏效。

你知道我错过了什么吗?

由于它抛出了一个关于代理的错误,您可以尝试将代理详细信息设置为GoogleGeocoder类。

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

相关内容

最新更新