6
當我運行下面的代碼(使用最新的Guzzle,v6)時,獲取請求的URL是http://example.com/foobar?foo=bar
從請求中刪除boo=far
。如何使用Guzzle結合默認查詢字符串參數和特定於請求的參數?
$guzzle_http_client = new GuzzleHttp\Client([
'base_uri' => 'http://example.com/',
'query' => [
'foo' => 'bar'
],
]);
$request = new \GuzzleHttp\Psr7\Request('GET', 'foobar?boo=far');
$response = $guzzle_http_client->send($request);
當我運行下面的代碼,通過boo=far
而不是作爲Client::send()
方法的一部分,被請求的URL是http://example.com/foobar?boo=far
$guzzle_http_client = new GuzzleHttp\Client([
'base_uri' => 'http://example.com/',
'query' => [
'foo' => 'bar'
],
]);
$request = new \GuzzleHttp\Psr7\Request('GET', 'foobar');
$response = $guzzle_http_client->send($request, ['query' => ['boo' => 'far']]);
當然,我希望被請求的URL是:
http://example.com/foobar?foo=bar&bar=foo
我該如何使Guzzle結合默認的客戶端查詢字符串參數與特定於請求的參數?
這是一個真正的痛苦!我用靜態方法'withQueryValue'創建了PSR7 \ Uri對象並將其傳遞給構造函數。但它也沒用! –