网址参数未发送进食

时间:2019-07-15 10:17:32

标签: php guzzle

今天是我刚接触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();

但是似乎我的参数根本不发送只是因为我的知识不足,你们在想什么?

1 个答案:

答案 0 :(得分:0)

form_params用于发送POST请求的参数。请改用query选项,该选项用于GET请求。在此处阅读文档:http://docs.guzzlephp.org/en/stable/request-options.html#query