libcurl在上传数据之前延迟1秒,命令行卷曲不会

fin*_*nnw 8 c curl libcurl mongoose-web-server

我正在使用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);
Run Code Online (Sandbox Code Playgroud)

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

$ curl --data-binary '<command>' http://127.0.0.1:12345/x
Run Code Online (Sandbox Code Playgroud)

它会立即发送请求,而不会受到1秒延迟的影响.

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


编辑服务器基于mongoose

fin*_*nnw 13

延迟的原因是:

客户端的解决方案是禁用Expect标头,如下所示:

headers = curl_slist_append(NULL, "Expect:");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
// ...
result = curl_easy_perform(curl);
curl_slist_free_all(headers);
Run Code Online (Sandbox Code Playgroud)

PHP客户端相关PHP问题的等效修复