发送 Post 请求打开海拔 API

Sending Post Request to Open Elevation API

我正在尝试向 Open Elevation API 发送一个 post 请求,这与他们在文档中所做的类似,但似乎犯了一个根本性错误,因为我只得到“未找到”作为错误返回。非常感谢有人发现我的错误,因为此时我不知所措。

(他们的文档: 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);```

我不知道你从哪里得到“方法地址”。该命令应该是“查找”。这给了我一个结果:

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);

结果:

{"results": [{"latitude": 10, "longitude": 10, "elevation": 515}, {"latitude": 20, "longitude": 20, "elevation": 545}, {"latitude": 41.161758, "longitude": -8.583933, "elevation": 117}]}