我想要一个curl
脚本来获取oneup api的响应。
api链接看起来像
curl https://api.oneup.com/v1/customers -u "api_12_e3ab@api.oneup.com:34a352e421d03a4qXqc91f9b48ed7eb02e5"
我的代码如下:
<?php
$url = "https://api.oneup.com/v1/customers -u 'api_133896_9f73@api.oneup.com:70213567295f25ba9fde5127a4348fa22c1b2789'";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13');
$output = curl_exec($ch);
curl_close($ch);
echo $output;
?>
我只获得输出1
答案 0 :(得分:3)
您需要授权:
curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
所有
<?php
$url = "https://api.oneup.com/v1/customers";
$username = 'api_133896_9f73@api.oneup.com';
$password = 'password';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13');
$output = curl_exec($ch);
curl_close($ch);
echo $output;
?>
请不要在此处发布安全凭证