https使用httpclient呼叫
我收到了一个400不好的请求,试图使用httpclient
调用API,但我不确定我缺少什么。
我尝试了浏览器和Postman的终点,但没有任何问题,但是当我尝试使用以下代码时,我会收到400个不好的请求:
using (HttpClient client = new HttpClient())
{
var result = client.GetAsync("https://api.exchange.coinbase.com/products/ETH-USD/candles?granularity=300&start=2022-03-22&end=2022-03-23").Result;
}
有人可以告诉我,我缺少什么来让这个工作来工作?
I am getting a 400 bad request trying to call an API using HttpClient
and I am not exactly sure what I am missing.
I have tried the endpoint from my browser and from Postman and have not had any issues, but when I try to use the following code I get a 400 bad request:
using (HttpClient client = new HttpClient())
{
var result = client.GetAsync("https://api.exchange.coinbase.com/products/ETH-USD/candles?granularity=300&start=2022-03-22&end=2022-03-23").Result;
}
Would anyone be able to tell me what I am missing to get this to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原始代码中的请求返回
{“ message”:“需要用户代理标头。”}
。如果是这种情况,请添加用户代理标头来解决问题The request from the original code returns
{"message":"User-Agent header is required."}
. If it is the case, add user-agent header to fix the problem