Translate cURL request to Guzzle

自古美人都是妖i 提交于 2019-12-04 06:24:42

Here is the solution:

$client = new \Guzzle\Http\Client();
$request = $client->get($url);

$request->getCurlOptions()->set(CURLOPT_SSL_VERIFYHOST, false);
$request->getCurlOptions()->set(CURLOPT_SSL_VERIFYPEER, false);
$request->getCurlOptions()->set(CURLOPT_RETURNTRANSFER, true);
$request->getCurlOptions()->set(CURLOPT_FOLLOWLOCATION, true);
$request->getCurlOptions()->set(CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$request->getCurlOptions()->set(CURLOPT_USERPWD, "$token:X");

$response = $request->send();

The solution I was able to get working for Guzzle6 is:

$headers = array();
$headers['grant_type'] = 'client_credentials';
$headers['client_id'] = $clientid;
$headers['client_secret'] = $clientSecret;

$response = $this->client->post($urlAuth, ['form_params' => $headers]);
$output = $response->getBody()->getContents();

ie the header array has to be wrapped in 'form_params'

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!