gpt4 book ai didi

c# - 调用基础 REST API

转载 作者:太空宇宙 更新时间:2023-11-03 15:38:18 24 4
gpt4 key购买 nike

我正在尝试调用需要 Accept 和 Authorization header 的 Base API。我在控制台应用程序中有以下代码,但总是收到 400 错误。我已经拦截了 fiddler 中的调用并且标题不存在。如果我在 fiddler 中手动创建它,则该调用有效。我是否遗漏了请求中的某些内容?

using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://api.getbase.com/");

client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

HttpResponseMessage response = await client.GetAsync("v2/users/self");

if (response.IsSuccessStatusCode)
{

}
}

这是文档 https://developers.getbase.com/docs/rest/articles/first_call

最佳答案

以下示例在使用 curl php 时有效,请注意带有“User-Agent”的行不要忘记 $ACESS_TOKEN。

$ch = curl_init('https://api.getbase.com/v2/leads');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'User-agent: '.$_SERVER['HTTP_USER_AGENT'], // USER-AGENT
'Content-Type: application/json; charset=utf-8',
'Authorization: Bearer ' .$ACCESS_TOKEN
)
);

关于c# - 调用基础 REST API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31105190/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com