在本地或在生产网站上运行的curl命令的结果不同

时间:2020-06-17 10:45:03

标签: php rest curl

我有一个旨在通过API注册用户的php文件。第一步是通过发布请求从API获取身份验证令牌。当我通过本地(通过Flywheel)wordpress网站运行它时,它会正确返回auth,但是当我在实时wordpress服务器上运行代码时,它将无法正常工作。

这是相关的代码。我可以肯定我传递的代理,机密和网址是正确的。

function getAuth($agent, $secret, $url) {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($curl, CURLOPT_USERPWD, $agent . ":" . $secret);
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Length: 0'));
    $result = curl_exec($curl);
    var_dump(curl_getinfo($curl) . '<br/>');
    var_dump(curl_errno($curl) . '<br/>');
    var_dump(curl_error($curl) . '<br/>');
    curl_close($curl);
    $array = json_decode($result, true);
    return $array;
} 

也许最让我烦恼的是我从var dumps收到的错误消息。 $array返回null。

string(10) "Array
" string(6) "0
" string(5) "

任何可以照亮的光线将不胜感激!

编辑:删除了类型转换,现在返回...事情了?

array(26){[“ url”] =>字符串(38)“ https://api.ce21.com/token/service/396” [[content_type“] =>字符串(9)” text / html“ [” http_code“] => int (502)[“ header_size”] => int(140)[“ request_size”] => int(258)[“ filetime”] => int(-1)[“ ssl_verify_result”] => int(0)[“ redirect_count“] => int(0)[” total_time“] => float(0.47892)[” namelookup_time“] => float(0.315523)[” connect_time“] => float(0.351211)[” pretransfer_time“] => float (0.441982)[“ size_upload”] => float(0)[“ size_download”] => float(1477)[“ speed_download”] => float(3089)[“ speed_upload”] => float(0)[“ download_content_length “] => float(1477)[” upload_content_length“] => float(-1)[” starttransfer_time“] => float(0.478869)[” redirect_time“] => float(0)[” redirect_url“] =>字符串(0)“” [“” primary_ip“] =>字符串(13)” 23.96.209.155“ [” certinfo“] => array(0){} [” primary_port“] => int(443)[” local_ip“] =>字符串(15)“ 162.241.252.215” [“ local_port”] =>整数(16238)}整数(0)字符串(0)“”

编辑两个:这是我正在使用https://api.ce21.com/interact/index#!/Tokens/Tokens_Post的API的文档

0 个答案:

没有答案