获取cUrl以抢先发送PHP进行DIGEST身份验证的Authorization标头 [英] Get cUrl to preemptively send Authorization header for DIGEST authentication in PHP

查看:623
本文介绍了获取cUrl以抢先发送PHP进行DIGEST身份验证的Authorization标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个PHP页面(实际上是WordPress插件),该页面通过DIGEST身份验证调用REST API.卷曲句柄是在每个请求的基础上创建的,具有给定的授权凭证并成功进行了身份验证.

We have a PHP page (actually a WordPress plugin) which makes calls to a REST API with DIGEST authentication. The curl handle is created on a per request basis, given authorisation credentials and successfully authenticates.

问题:

在后台,Curl正在发送两个请求.第一个失败,并带有401和一个挑战,第二个包含Authorization标头并成功(200)

Under the hood, Curl is sending two requests. The first fails with a 401 and a challenge, the second contains an Authorization header and succeeds (200)

随后的API调用之后,cUrl继续发送两个请求.这似乎效率很低,导致在操作期间增加了2倍的网络延迟.

Upon subsequent API calls cUrl continues to send two requests. This seems inefficient, causing 2 x network latency to be added to the duration of the operation.

我们如何使cURL抢先验证"(示例)将来的要求?

How do we cause cURL to "pre-emptively authenticate" (example) future requests?

Curl Multi具有此功能吗?

Does Curl Multi have this feature?

推荐答案

您必须重新使用相同的curl句柄:请参见

You must re-use the same curl handle: see this similar question for more details.

就多接口而言,您还需要显式重用每个句柄以利用摘要访问身份验证请求计数器,即,牢记C API:

As far as the multi interface is concerned you also need to explicitly reuse each handle to leverage the Digest Access Authentication request counter, i.e. with the C API in mind:

  1. 使用curl_multi_remove_handle
  2. 从多手柄中移除手柄
  3. curl_easy_reset
  4. 重置
  5. 设置下一个通话的选项
  6. 使用curl_multi_add_handle
  7. 将其重新添加到多手柄中
  1. remove your handle from the multi handle with curl_multi_remove_handle
  2. reset it with 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以抢先发送PHP进行DIGEST身份验证的Authorization标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆