我正在使用 CURLOPT_POST 发送 https 消息。在运行过程中,我的应用程序停留在:
期望:100-继续
完成等待 100-继续
From 乔治的日志——当curl发送100-继续时 https://gms.tf/when-curl-sends-100-continue.html,您可以设置Expect
标头为空字符串:
curl -X POST -H "Expect:" http://mywebsite.com/an/endpoint -F data=@myfile
解释
特别是,您可以在放置/发布请求中设置一个空的“Expect:”标头。我在curl的回调后教程中找到了一些示例代码,其中包含以下带有DISABLE_EXPECT“喷嚏”防护的代码片段:
#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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)