今天是我刚接触Guzzle的第一天,我试图将参数发送到网站,但没有发送。然后我决定找出问题,并创建了一个简单的脚本来打印我的get请求
echo $_GET['locationId'];
在这里,我正在发送请求
require "./vendor/autoload.php";
use GuzzleHttp\Client;
$client = new Client([
"base_uri" => "http://avto.com/",
"version" => "1.1",
"headers" => [
'cache-control' => 'no-cache',
'Connection' => 'keep-alive',
'accept-encoding' => 'gzip, deflate',
'Host' => 'www.avito.ru',
'Cache-Control' => 'no-cache',
'Accept' => '*/*',
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
]
]);
$response = $client->request("GET","test.php",[
"form_params" => [
"locationId" => "650370"
],
]);
echo $response->getBody()->getContents();
但是似乎我的参数根本不发送只是因为我的知识不足,你们在想什么?
答案 0 :(得分:0)
form_params
用于发送POST请求的参数。请改用query
选项,该选项用于GET请求。在此处阅读文档:http://docs.guzzlephp.org/en/stable/request-options.html#query