I have the following cmd and its work. - using digest auth - using json data
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_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? Thanks for help
Finally, I check the message different between two method. I found that TCP_NODELAY
and USERAGENT
used in cURL. I need to add these two command.
Just add --libcurl -filename.c
after your curl command. This will create a C source file performing the exact same operation as your curl command.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.