简体   繁体   English

如何将cURL转换为libcurl(c)

[英]How to convert cURL to libcurl(c)

I have the following cmd and its work. 我有以下cmd及其工作。 - using digest auth - using json data -使用摘要身份验证-使用json数据

curl -v --digest -u user:passwd -X POST http://192.168.139.65:80/digest/getMode -H "Content-Type: application/json" -d '{"Data":{}}'

I would like to convert cURL to libcurl. 我想将cURL转换为libcurl。

curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.139.65:80/digest/getMode");
headerlist = curl_slist_append(headerlist, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_easy_setopt(curl, CURLOPT_USERPWD, "user:passwd ");
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"Data\":\t{}\r\n}");

curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

But I got fail, It return 401. Is there any missing? 但是我失败了,它返回401。是否缺少任何内容? Thanks for help 感谢帮助

Finally, I check the message different between two method. 最后,我检查两种方法之间的消息不同。 I found that TCP_NODELAY and USERAGENT used in cURL. 我发现在cURL中使用了TCP_NODELAYUSERAGENT I need to add these two command. 我需要添加这两个命令。

Just add --libcurl -filename.c after your curl command. 只需在curl命令之后添加--libcurl -filename.c This will create a C source file performing the exact same operation as your curl command. 这将创建一个C源文件,执行与curl命令完全相同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM