Reputation: 503
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
Upvotes: 1
Views: 382
Reputation: 383
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.
Upvotes: 4
Reputation: 503
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.
Upvotes: -2