curl_slist_append增加http header -- curl

来源:互联网 发布:淘宝宝贝复制大师 编辑:程序博客网 时间:2024/06/04 18:10
 CURL的中文资料比较少,下面是实际工作中用到,摸索出来的,记录之。

1、增加HTTP Header
   curl_slist *plist = curl_slist_append(NULL, "Client-Key:m-5be02cd9ddfb11dcaf9700142218fc6e");
   curl_slist_append(plist, "username:winter_445@163.com");
   curl_slist_append(plist, "password:123456");
   curlRet = curl_easy_setopt(m_hCURL, CURLOPT_HTTPHEADER, plist);
   这样即可在HTTP Header中加入上面的内容。

2、增加Post Form的数据
   curlRet = curl_easy_setopt(m_hCURL,CURLOPT_POSTFIELDS, "Client-Key=m-5be02cd9ddfb11dcaf9700142218fc6e&username=winter_445@163.com&password=123456");
   像上面那样,可以在Post表单中加上任意数据。

3、让CURL记录Cookie
   curlRet = curl_easy_setopt(m_hCURL, CURLOPT_COOKIEFILE, "");
   curlRet = curl_easy_setopt(m_hCURL, CURLOPT_COOKIEJAR, "");
   像上面那样设置一下,试验中发现不需要指定cookie文件名它也能工作,具体这两个设置有没会差别,暂不清楚,互联网上也有人提问此问题。

4、Other
0 0
原创粉丝点击