【发布时间】:2022-05-10 19:35:04
【问题描述】:
我正在使用 CURLOPT_POST 发送 https 消息。在运行过程中,我的应用程序卡在:
期望:100-继续
等待 100-继续
【问题讨论】:
标签: libcurl
我正在使用 CURLOPT_POST 发送 https 消息。在运行过程中,我的应用程序卡在:
期望:100-继续
等待 100-继续
【问题讨论】:
标签: libcurl
从George's Log -- When curl sends 100-continue,您可以将Expect 标头设置为空字符串:
curl -X POST -H "Expect:" http://mywebsite.com/an/endpoint -F data=@myfile
特别是,您可以在 put/post 请求中设置一个空的“Expect:”标头。我在 curl 的回调后教程中找到了一些示例代码,其中包含以下带有 DISABLE_EXPECT“喷嚏”防护的 sn-p:
#ifdef DISABLE_EXPECT
/*
Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue"
header. You can disable this header with CURLOPT_HTTPHEADER as usual.
NOTE: if you want chunked transfer too, you need to combine these two
since you can only set one list of headers with CURLOPT_HTTPHEADER. */
/* A less good option would be to enforce HTTP 1.0, but that might also
have other implications. */
{
struct curl_slist *chunk = NULL;
chunk = curl_slist_append(chunk, "Expect:");
res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
/* use curl_slist_free_all() after the *perform() call to free this
list again */
}
#endif
我保留了一个用于放置/发布请求的标头列表。将上述内容添加到该列表中的效果与宣传的一样:
// Disable Expect: 100-continue
vc->slist = curl_slist_append(vc->slist, "Expect:");
...
curl_easy_setopt(vc->curl, CURLOPT_HTTPHEADER, vc->slist);
【讨论】: