Guzzle 3/4 - 无法发布

时间:2015-01-31 19:29:51

标签: php curl guzzle

我将此代码转换为Guzzle(Guzzle3和Guzzle4 = GuzzleHttp)时遇到问题。正如你所看到它使用 BASIC AUTH ,相信我,我已经尝试了很多组合,任何想法?谢谢

function get_auth($params) {

$client_id = 'name';
$secret = 'WEirdCombINationOfCharacters';

$opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&');
$opts[CURLOPT_RETURNTRANSFER] =  true;
$opts[CURLOPT_FRESH_CONNECT] =  true;
$opts[CURLOPT_USERPWD] = "$client_id:$secret";
$opts[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
$opts[CURLOPT_URL] =  'https://address.com/oauth/token';

$ch = curl_init();

curl_setopt_array($ch, $opts);
$result = curl_exec($ch);
curl_close($ch);
$result_object = json_decode($result);

if($result_object->error_description) trigger_vg_error($result_object->error_description);

return $result_object;
}

1 个答案:

答案 0 :(得分:0)

只留下痕迹(使用Guzzle 3) BASIC_AUTH

$http = new Client('https://asite.com', array(
    'request.options' => array(
        'auth' => array($client_id, $client_secret, 'Basic')
    )

$request = $http->post('/oauth/token', null, array(
        'code'          => $_GET['code'],
        'grant_type'    => 'authorization_code'
    ));