gpt4 book ai didi

c - libcurl 在上传数据前延迟 1 秒,命令行 curl 不会

转载 作者:太空狗 更新时间:2023-10-29 17:00:56 25 4
gpt4 key购买 nike

我正在使用 libcurl 将 API 命令发送到本地服务(即在 127.0.0.1 上)。

该程序旨在替换 shell 脚本(使用 curl 程序。)

一切正常,除了某处有 1 秒的延迟,即从我调用 curl_easy_perform() 到我的读取回调函数首次被调用之间经过了 1 秒。

C 程序正在使用这些选项(省略了错误检查和回调代码):

curl_easy_setopt(curl, CURLOPT_URL, "http://127.0.0.1:12345/x");
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
curl_easy_setopt(curl, CURLOPT_INFILESIZE, (long)getLengthOfCommandObject());
curl_easy_setopt(curl, CURLOPT_READFUNCTION, &myReadFunction);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &myWriteFunction);

但是如果我像这样从 shell 运行 curl:

$ curl --data-binary '<command>' http://127.0.0.1:12345/x

它立即发送请求,不会有 1 秒的延迟。

可能导致延迟的原因是什么,我可以设置一个选项来防止延迟吗?


编辑 服务器基于mongoose

最佳答案

延迟的原因是:

客户端的解决方案是像这样禁用 Expect header :

headers = curl_slist_append(NULL, "Expect:");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
// ...
result = curl_easy_perform(curl);
curl_slist_free_all(headers);

Equivalent fix for PHP clientrelated PHP question

关于c - libcurl 在上传数据前延迟 1 秒,命令行 curl 不会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17383089/

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