gpt4 book ai didi

c - 在 C 中的 libcurl 库中设置标题标志选项

转载 作者:行者123 更新时间:2023-12-05 01:29:12 27 4
gpt4 key购买 nike

我正在执行 Post 请求,为此我必须将 header 内容类型设置为 application/json为此,我正在编写以下代码:

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Accept: application/json");
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "charsets: utf-8");
res = curl_easy_setopt(curl, CURLOPT_HEADER,headers);

但是当我编译程序时,错误是
Accept: */*
Proxy-Connection: Keep-Alive
Content-Length: 22
Content-Type: application/x-www-form-urlencoded

请帮我将此内容类型设置为 application/json尽早

最佳答案

你必须把你的标题...

CURLOPT_HTTPHEADER

...尽管...
CURLOPT_HEADER

...旨在在输出中包含标题

所以你的解决方案可以只是替换 CURLOPT_HEADERCURLOPT_HTTPHEADER

关于c - 在 C 中的 libcurl 库中设置标题标志选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14276807/

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