简体   繁体   English

获取cUrl以抢先发送PHP进行DIGEST身份验证的Authorization标头

[英]Get cUrl to preemptively send Authorization header for DIGEST authentication in PHP

We have a PHP page (actually a WordPress plugin) which makes calls to a REST API with DIGEST authentication. 我们有一个PHP页面(实际上是WordPress插件),该页面通过DIGEST身份验证调用REST API。 The curl handle is created on a per request basis, given authorisation credentials and successfully authenticates. 卷曲句柄是在给定授权凭证的情况下基于请求创建的,并成功进行了身份验证。

PROBLEM: 问题:

Under the hood, Curl is sending two requests. 在后台,Curl正在发送两个请求。 The first fails with a 401 and a challenge, the second contains an Authorization header and succeeds (200) 第一个失败,显示401和质询,第二个包含Authorization标头并成功(200)

Upon subsequent API calls cUrl continues to send two requests. 在随后的API调用中,cUrl继续发送两个请求。 This seems inefficient, causing 2 x network latency to be added to the duration of the operation. 这似乎效率低下,导致2倍的网络延迟被添加到操作期间。

How do we cause cURL to "pre-emptively authenticate" ( example ) future requests? 我们如何使cURL未来请求“抢先验证”( 例如 )?

Does Curl Multi have this feature? Curl Multi是否具有此功能?

You must re-use the same curl handle: see this similar question for more details. 您必须重新使用相同的卷曲手柄:有关更多详细信息,请参见此类似问题

As far as the multi interface is concerned you also need to explicitly reuse each handle to leverage the Digest Access Authentication request counter, ie with the C API in mind: 就多接口而言,您还需要显式重用每个句柄以利用摘要访问身份验证请求计数器,即,牢记C API:

  1. remove your handle from the multi handle with curl_multi_remove_handle 使用curl_multi_remove_handle从多手柄中删除手柄
  2. reset it with curl_easy_reset curl_easy_reset重置它
  3. set the options for the next call 设置下一个通话的选项
  4. re-add it into the multi handle with curl_multi_add_handle 使用curl_multi_add_handle将其重新添加到多句柄中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM