gpt4 book ai didi

c - 使用 libcurl 使 https get

转载 作者:太空狗 更新时间:2023-10-29 17:12:01 28 4
gpt4 key购买 nike


我正在尝试连接到 google api。
这在我的终端上工作正常,我正在做:
curl https://www.googleapis.com/tasks/v1/users/@me/lists --header "Authorization: Bearer myAccessCode"
这工作正常,但现在我想在 c 程序中制作它。
为此,我有:

    CURL *curl;
char *header = "Authorization: Bearer myAccessCode";
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, header);

curl = curl_easy_init();

char *response = NULL;

curl_easy_setopt(curl, CURLOPT_URL, "https://www.googleapis.com/tasks/v1/users/@me/lists");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);

curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);

curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, httpsCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);

curl_easy_perform(curl);
curl_easy_cleanup(curl);

但在这里我只是收到一条消息,要求登录。我不知道我做错了什么,有没有人看到我的失败?

最佳答案

就像我在上面的评论中写的那样:
我刚刚意识到我做了:curl_slist_append(headers, header);
而不是:headers = curl_slist_append(headers, header);
所以 headers 总是 NULL 并且我在没有 header 的情况下发出了 get 请求。
(我在上面的问题中编辑了它,所以代码可以工作,如果有的话)

关于c - 使用 libcurl 使 https get,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10210741/

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