2017-03-01 96 views
3

我有一個方法,使用gullzehttp,並想將其更改爲池加上池實現了請求方法狂飲請求查詢參數

<?php 
use GuzzleHttp\Client; 
$params = ['password' => '123456']; 
$header = ['Accept' => 'application/xml']; 
$options = ['query' => $params, 'headers' => $header]; 
$response = $client->request('GET', 'http://httpbin.org/get', $options); 

我需要改變,以請求方法,但我找不到在文檔中如何在請求中發送查詢字符串變量

<?php 
use GuzzleHttp\Psr7\Request; 
$request = new Request('GET', 'http://httpbin.org/get', $options); 

回答

1

您需要將查詢作爲字符串添加到URI。

對於您可以使用http_build_queryguzzle helper function到參數數組轉換爲編碼的查詢字符串:

$uri = new Uri('http://httpbin.org/get'); 

$request = new Request('GET', $uri->withQuery(GuzzleHttp\Psr7\build_query($params))); 

// OR 

$request = new Request('GET', $uri->withQuery(http_build_query($params)));