如何使用摘要与libcurl的身份验证POST HTTP请求 [英] How to post http request using digest authentication with libcurl
问题描述
我试图执行一个POST请求,我试图与摘要式身份验证做到这一点。与的libcurl
,我设置的选项:
I'm trying to perform a post request and I'm trying to do it with the digest authentication. with libcurl
, I set the options:
url_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_easy_setopt(curl_handle, CURLOPT_USERPWD, "user:pdw");
设置所有其他选项(邮局,URL和一切)之前。服务器关闭我的连接,我认为没有消化而成。我只是不知道如何自动获得摘要的质询 - 响应行为。如果我设置 HTTPAUTH
到 CURLAUTH_BASIC
它的连接codeS 的东西,我看带有verbose选项包含 =授权基本报头
。随着消化没有标题。
before setting all the other option (post, url and everything). The server closes my connection and I think that no digest is made. I just don't know how automatically obtain the challenge-response behavior of the digest. If I set HTTPAUTH
to CURLAUTH_BASIC
it encodes the stuff, I see with the VERBOSE option the header containing authorization = basic
. With digest no headers.
你知道我怎么能做到这一点,或者你可以给我一些例子吗?我真的搜索无处不在。
Do you know how can I do it, or can you give me some example? I really search everywhere.
推荐答案
有关基本 POST
要求你应该做的:
For a basic POST
request you should do:
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
(a.k.a 的multipart / form-data的
)
For a multipart POST
(a.k.a 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");
临提示:使用卷曲
与命令行工具 - libcurl的request.c
:它输出到这个C文件中用来执行相应的请求的选项列表。
Pro-tip: use curl
command-line tool with --libcurl request.c
: it outputs into this C file the list of options used to perform the corresponding request.
这篇关于如何使用摘要与libcurl的身份验证POST HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!