好的,我用了"guzzlehttp://guzzle":"~6.0"作为laravel。
它在服务器上工作,但在我的XAMPP上不工作,我不知道问题出在哪里。这是错误代码。
传递给GuzzleHttp''Client::request()的参数3必须为数组类型,给定为布尔值
这是代码:
$param_data = array(
'api_user' => Config::get('sendgrid.api_user'),
'api_key' => Config::get('sendgrid.api_key'),
'list' => Config::get('sendgrid.list'),
'email' => 'xxxxxxx@yahoo.com',
);
$client = new Client();
$client->setDefaultOption('verify', false);
$res = $client->request(
'GET',
'https://api.sendgrid.com/api/newsletter/lists/email/get.json',
[
'query' => $param_data
]
);
$arr_res = json_decode($res->getBody());
print_r( $arr_res );
我在代码中解决了同样的错误
$param_data = array(
'api_user' => Config::get('sendgrid.api_user'),
'api_key' => Config::get('sendgrid.api_key'),
'list' => Config::get('sendgrid.list'),
'email' => 'xxxxxxx@yahoo.com',
);
$client = new Client();
$client->setDefaultOption('verify', false);
$res = $client->request(
array(
'GET',
'https://api.sendgrid.com/api/newsletter/lists/email/get.json?query='.$param_data,
));
$arr_res = json_decode($res->getBody());
print_r( $arr_res );
另外,如果您在同一个页面中使用Laravel请求和Guzzle请求,那么您需要像这样使用它。
use Illuminate'Http'Request;
use GuzzleHttp'Psr7'Request as GuzzleRequest;
试试这个,希望它能为你工作:)
阅读guzzle文档后,我更改了请求的结构:
$client = new Client([
// Base URI is used with relative requests
'base_uri' => 'https://mytesturl.com/',]);
$res = $client->request('GET', 'processJobs', ['verify' => false]);
$arr_res= json_decode($res->getBody());
echo $arr_res;
问题在于请求方法如何接收参数,有很多方法可以构建请求,但如果出现此消息。我建议使用这种方式