Guzzle 5中的URI模板? [英] URI templates in Guzzle 5?
本文介绍了Guzzle 5中的URI模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
枪手3 具有允许请求定义的URI模板,例如
Guzzle 3 had URI templates that allowed for a request definition such as
$request = $client->get(array('http://example.com{+path}{/segments*}{?query,data*}', array(
'path' => '/foo/bar',
'segments' => array('one', 'two'),
'query' => 'test',
'data' => array(
'more' => 'value'
)
)));
就我而言,我想利用'segments',但是 Guzzle 5 似乎没有对此进行定义.
In my case, i am looking to exploit the 'segments', but Guzzle 5 doesn't seem to define this.
相反,最接近的我是
* $client = new Client([
* 'base_url' => [
* 'http://www.foo.com/{version}/',
* ['version' => '123']
* ],
* 'defaults' => [
* 'timeout' => 10,
* 'allow_redirects' => false,
* 'proxy' => '192.168.16.1:10'
* ]
* ]);
但是,正如您所见,这适用于base_url
But, this as you see applies to the base_url
反正我可以像Guzzle 3一样使用URI模板吗?
Is there anyway i can use a URI template like the one in Guzzle 3?
推荐答案
自创建帖子以来,您可能已经找到了答案,但这是如何在Guzzle 5中使用URI模板(有一个简单的示例):
You might have found the answer since you created the post, but here is how to use URI templates with Guzzle 5 (with a simpler example):
$client = new Client([
'base_url' => 'https://api.github.com',
]);
$response = $client->get(
['/users/{username}', ['username' => $username]], // URI template & Parameters
['future' => true] // Options
);
这篇关于Guzzle 5中的URI模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文