Search code examples
c#wpfhttpwebrequest

Error 407 (Proxy Authentication Request) on Web Request via Geocoding API


I'm writing a piece of code that will take in addresses input by the user, and return the latitude/longitude values for later use. For this, I'm using the Geocoding API. What I have is:

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 is a Textbox where the user types in the addresses. However, I get the 407 Error when I run it.

I've read many questions and tried their solutions (like this one, or this one), but none have worked.

Any ideas on what I'm missing?


Solution

  • Since it is throwing an error regarding proxy, you can try setting your proxy details to GoogleGeocoder class.

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