c - 如何使用带有 libcurl 的摘要身份验证发布 http 请求

标签 c libcurl digest

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

curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);

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

在设置所有其他选项(post、url 和所有内容)之前。服务器关闭了我的连接,我认为没有生成摘要。只是不知道如何自动获取摘要的挑战-响应行为。如果我将 HTTPAUTH 设置为 CURLAUTH_BASIC编码这些东西,我看到带有 VERBOSE 选项的 header 包含 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");

对于多部分 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 文件中请求。

关于c - 如何使用带有 libcurl 的摘要身份验证发布 http 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16800640/

相关文章:

c - C中结构的动态分配

c - 由于无效指针而出现段错误

c++ - 无法编译 libcurl 的静态库

php - 如何使用 libcurl 从用 C++ 编写的游戏发布到我服务器上的 php 页面更安全?

r - 为 R 中的字符串创建唯一的、人类可读的标识符(哈希?)

c - 文件范围内的可变长度数组?

c - 使用 libcurl 使 https get

java - 使用 iText 库在 pdf 中插入隐藏摘要

XML 签名 : How to calculate the digest value?

CUDA 链接错误未定义引用