[英]How do i do a request to a third party api? using httpclient
Currently, I need to integrate the CoinGecko API, this is a free API open to the public. 目前,我需要集成CoinGecko API,这是一个向公众开放的免费API。 ( https://www.coingecko.com/api/docs/v3 )
( https://www.coingecko.com/api/docs/v3 )
The HTTP client sends the request but it never returns a response HTTP客户端发送请求但它永远不会返回响应
string BaseUrl = "https://api.coingecko.com/api/v3";
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(BaseUrl);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync("/coins/list");
if (response.IsSuccessStatusCode)
{
var data = await response.Content.ReadAsStringAsync();
var table = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Models.Coins>>(data);
}
The expected result is that it should return the coins list, but it never does. 预期的结果是它应该返回硬币列表,但它永远不会。
Change BaseUrl to: 将BaseUrl更改为:
string BaseUrl = "https://api.coingecko.com";
and the GetAsync call to 和GetAsync调用
HttpResponseMessage response = await client.GetAsync("/api/v3/coins/list");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.