且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使的libcurl发送摘要认证报头中的每个HTTP数据包?

更新时间:2022-02-11 21:29:13

要获得你需要这样的行为的再利用你卷曲处理作为后续调用,以充分利用持久连接和 HTTP摘要认证请求计数器:

To obtain such a behavior you need to re-use you curl handle for the subsequent calls to take full advantage of persistent connections and Digest Access Authentication request counter:

[...]客户端可能会使另一个请求,重用服务器随机数值(服务器只发出对每一个401响应新的随机数),但提供了一个新的客户端随机数(cnonce)。对于后续的请求,十六进制请求计数器(NC)必须比以前的最后一个值大于

[...] the client may make another request, reusing the server nonce value (the server only issues a new nonce for each "401" response) but providing a new client nonce (cnonce). For subsequent requests, the hexadecimal request counter (nc) must be greater than the last value it used

在实践中不清理你的卷曲处理。相反,维护它,一旦需要执行另一项要求:

In practice do not clean up your curl handle. Instead maintain it and as soon as you need to perform another request:


  • curl_easy_reset 功能重置: curl_easy_reset (卷曲);

  • 然后重新设置选项。

  • reset it with the curl_easy_reset function: curl_easy_reset(curl);
  • then re-set your options.

如果您使用 CURLOPT_VERBOSE 选项,你会看到,你将有一个授权头后续请求( NC = 00000002 NC = 00000003 等)越来越请求计数器。

If you use the CURLOPT_VERBOSE option you will see that for the subsequent requests you will have an Authorization header with an increasing request counter (nc=00000002, nc=00000003, etc).