本文介绍了如何在PHP中使用卷曲基本授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有基本的授权PHP卷曲的要求的问题。
这里是命令行卷曲
i am having problem with php curl request with basic authorization.here is the command line curl
curl -H "Accept: application/product+xml" "https://{id}:{api_key}@api.domain.com/products?limit=1&offset=0"
我已经通过以下方式设置卷曲头尝试,但它不是wroking
i have tried by setting curl header in following ways but it's not wroking
Authorization: Basic id:api_key
or
Authorization: Basic {id}:{api_key}
但它不工作,我得到了响应请求验证参数丢失或无效的,但我已经使用正确的ID和API_KEY这是在命令行卷曲的工作(我测试)
but it's not working, i got response "authentication parameter in the request are missing or invalid" but i have used proper id and api_key which is working in command line curl(i tested)
请帮我。
问候
阿明
推荐答案
尝试以下code:
$username='ABC';
$password='XYZ';
$URL='<URL>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code
$result=curl_exec ($ch);
curl_close ($ch);
这篇关于如何在PHP中使用卷曲基本授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!