简体   繁体   English

cURL 命令行到 php 版本

[英]cURL Commandline to php version

when I use the following on command line I am getting the output perfectly.当我在命令行上使用以下内容时,我得到了完美的输出。

curl -X GET -H "Authorization: sso-key API_KEY:API_SECRET" "https://api.godaddy.com/v1/domains/mydomain.com"

but when I try to get this from PHP using the following code但是当我尝试使用以下代码从 PHP 获取它时

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Authorization: sso-key API_KEY:API_SECRET"]);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "API_KEY:API_SECRET");
$result=curl_exec ($ch);

curl_close ($ch);

var_dump($result);

I failed to get anything.我什么都没得到。

what am I missing here?我在这里错过了什么?

$URL = "https://api.godaddy.com/v1/domains/mydomain.com";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Authorization:  sso-key API_KEY:API_SECRET"]);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);

$result=curl_exec ($ch);

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
var_dump($result);
var_dump($httpCode);

curl_close ($ch);

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

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