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?

1
  • 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. Commented Nov 19, 2018 at 18:12

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Will try now. Thank's
Yeah, that helps. Thank's!
a suggestion: NotFound is usually URL related. You can use a URL builder to build your GET requests stackoverflow.com/a/41416363/7927820

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.