我正在尝试执行发布请求,并且正在尝试使用摘要身份验证来执行此操作。有libcurl
,我设置的选项:
curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_easy_setopt(curl_handle, CURLOPT_USERPWD, "username:password");
Run Code Online (Sandbox Code Playgroud)
在设置所有其他选项(post、url 和所有内容)之前。服务器关闭了我的连接,我认为没有进行任何摘要。我只是不知道如何自动获取摘要的挑战响应行为。如果我设置HTTPAUTH
为CURLAUTH_BASIC
它对内容进行编码,我会使用 VERBOSE 选项看到包含authorization = basic
. 摘要没有标题。
你知道我该怎么做吗,或者你能给我举个例子吗?我真的到处找。
对于基本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");
Run Code Online (Sandbox Code Playgroud)
对于多部分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");
Run Code Online (Sandbox Code Playgroud)
专业提示:使用curl
命令行工具--libcurl request.c
:它将用于执行相应请求的选项列表输出到此 C 文件中。