3

我正在尝试执行发布请求,并且正在尝试使用摘要身份验证来执行此操作。,libcurl我设置选项:

curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);

curl_easy_setopt(curl_handle, CURLOPT_USERPWD, "username:password");

在设置所有其他选项(帖子、网址和所有内容)之前。服务器关闭了我的连接,我认为没有生成摘要。我只是不知道如何自动获取摘要的挑战响应行为。如果我设置它对内容HTTPAUTH进行编码,我会使用 VERBOSE 选项看到包含. 有摘要没有标题。CURLAUTH_BASICauthorization = basic

你知道我该怎么做,或者你能给我一些例子吗?我真的到处找。

4

1 回答 1

6

对于基本POST请求,您应该这样做:

curl_easy_setopt(hnd, CURLOPT_USERPWD, "user:pwd");
curl_easy_setopt(hnd, CURLOPT_HTTPAUTH, (long)CURLAUTH_DIGEST);
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");

对于多部分POST(又名multipart/form-data):

struct curl_httppost *post;
struct curl_httppost *postend;
/* setup your POST body with `curl_formadd(&post, &postend, ...)` */
curl_easy_setopt(hnd, CURLOPT_USERPWD, "user:pwd");
curl_easy_setopt(hnd, CURLOPT_HTTPPOST, post);
curl_easy_setopt(hnd, CURLOPT_HTTPAUTH, (long)CURLAUTH_DIGEST);
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");

专业提示:使用curl命令行工具--libcurl request.c:它将用于执行相应请求的选项列表输出到此 C 文件中。

于 2013-05-29T07:50:53.950 回答