[英]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:
curl_multi_remove_handle
curl_multi_remove_handle
从多手柄中删除手柄 curl_easy_reset
curl_easy_reset
重置它 curl_multi_add_handle
curl_multi_add_handle
将其重新添加到多句柄中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.