How to disable Expect 100 continue in libcurl

感情迁移 提交于 2019-12-11 15:54:55

问题


I am using CURLOPT_POST to send an https message. During running, my application stuck at:

Expect: 100-continue

Done waiting for 100-continue


回答1:


I just ran into this issue earlier today. i found the following page that also talks about it and suggests how to disable:

George's Log -- When curl sends 100-continue

In particular you can set an empty "Expect:" header in your put / post request. i found some sample code in the post-callback tutorial for curl that contains the following snippet with a DISABLE_EXPECT "sneeze" guard:

#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

i keep an slist of headers to use for put / post requests. adding the equivalent of the above to that list works as advertised:

// Disable Expect: 100-continue
vc->slist = curl_slist_append(vc->slist, "Expect:");
...
curl_easy_setopt(vc->curl, CURLOPT_HTTPHEADER, vc->slist);


来源:https://stackoverflow.com/questions/49670008/how-to-disable-expect-100-continue-in-libcurl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!