GoogleMaps + c #

1

I'm trying to make a request in C # using the package RestSharp , to obtain geolocation information by passing the zip. The request looks like this:

RestClient client = new RestClient("https://maps.googleapis.com/maps/api/geocode/json?address=" + cep + "&key=" + key);
RestRequest request = new RestRequest(Method.GET);

IRestResponse response = client.Execute(request);

But I only get TimeOut .

The strange thing is that if I run this URL in my browser, I get results.

Can anyone help me please?

    
asked by anonymous 04.01.2019 / 16:11

2 answers

0

Try it this way:

var client = new RestClient("https://maps.googleapis.com/");
var request = new RestRequest(Method.GET);

request.Resource = "maps/api/geocode/json?address={cep}&key={key}";
request.AddParameter("cep", cep, ParameterType.UrlSegment);
request.AddParameter("key", key, ParameterType.UrlSegment);

var response = client.Execute(request);

Another way, this time with WebRequest :

string url = $"https://maps.googleapis.com/maps/api/geocode/json?address={cep}&key={key}";

WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse();

Stream data = response.GetResponseStream();
StreamReader reader = new StreamReader(data);

string responseFromServer = reader.ReadToEnd();

response.Close();
    
04.01.2019 / 16:36
0

The problem is that in my company the proxy was blocking the calls made by .NET applications! I ran the test using another network and it worked fine.

Thank you all for helping me ..

    
04.01.2019 / 17:40