0

I have a method, that sends city to Google Geocoding API.

Here is this method.

public static async Task<string> ChangeDestination(string city_name) 
{
    string result;
    var realm = Realm.GetInstance();
    var client = new RestClient("https://maps.googleapis.com/maps/api/geocode/json?address=");
    var request = new RestRequest(city_name+"&key=***************", Method.GET);
    IRestResponse response = await client.ExecuteTaskAsync(request);
    var content = response.Content;
    var responseData1 = JsonConvert.DeserializeObject<ChangeLocation>(content);

    result = "hey";
    return result;
}

In content I get Not Found.

enter image description here

When I try this request from the postman. I get JSON.

Where can be my problem?

Fábio Nascimento
  • 2,644
  • 1
  • 21
  • 27
Eugene Sukh
  • 2,357
  • 4
  • 42
  • 86
  • Not familiar with RestClient but you should probably create it with the URL only, i.e. remove ? and add address= to the Request rather than mixing the query string between the two. – Alex K. Nov 19 '18 at 18:12

1 Answers1

2

It's because RestClient takes a baseUrl as parameter, and to RestRequest you should pass the resource:

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

For all HTTP request issues, you might find Fiddler useful.

Kristoffer Jälén
  • 4,112
  • 3
  • 30
  • 54