I am trying to send a post request to the Open Elevation API similarly to what they did in their documentation, but seem to make a fundamental mistake since I only get "not found" back as an error. Would really appreciate someone finding my error since I am at a loss at this point.
(Their documentation: https://github.com/Jorl17/open-elevation/blob/master/docs/api.md)
client.BaseAddress = new Uri("https://api.open-elevation.com/api/v1/lookup");
var content = new StringContent("{\"locations\":[{\"latitude\":10,\"longitude\":10},{\"latitude\":20,\"longitude\":20},{\"latitude\":41.161758,\"longitude\":-8.583933}]}", System.Text.Encoding.UTF8, "application/json");
var result = await client.PostAsync("Method Address", content);
string resultContent = await result.Content.ReadAsStringAsync();
Console.Write(resultContent);```
CodePudding user response:
I don't know where you get the "Method Address" from. The command should be "lookup". This gives me a result:
var client = new HttpClient();
client.BaseAddress = new Uri("https://api.open-elevation.com/api/v1/");
var content = new StringContent("{\"locations\":[{\"latitude\":10,\"longitude\":10},{\"latitude\":20,\"longitude\":20},{\"latitude\":41.161758,\"longitude\":-8.583933}]}", System.Text.Encoding.UTF8, "application/json");
var result = await client.PostAsync("lookup", content);
string resultContent = await result.Content.ReadAsStringAsync();
Console.Write(resultContent);
Result:
{"results": [{"latitude": 10, "longitude": 10, "elevation": 515}, {"latitude": 20, "longitude": 20, "elevation": 545}, {"latitude": 41.161758, "longitude": -8.583933, "elevation": 117}]}