Guzzle6 中的 URI 模板?
URI templating in Guzzle6?
我无法在 Guzzle 6 中使用 URI 模板。
我的代码(更新):
self::$client = new Client(["base_uri" => "http://example.com/api/", "cookies" => true]);
$result = self::$client->get(["project/{projectId}", ["projectId" => $projectId]]);
我已经检查了 this old documentation and this 个问题,但无法解决。
抛出的异常是:URI 必须是字符串或 UriInterface。
我找不到与 Guzzle 6 相关的任何文档。
Guzzle 的 get
方法定义是 get(string|UriInterface $uri, array $options = [])
并且您将数组作为 $uri
传递,这在此处是不允许的。
你必须自己构建 uri,因为 guzzle 不会为你做那件事。
正确的代码块应该如下所示(如果 projectId
是整数):
$result = self::$client->get(sprintf('project/%d', $projectId));
我无法在 Guzzle 6 中使用 URI 模板。
我的代码(更新):
self::$client = new Client(["base_uri" => "http://example.com/api/", "cookies" => true]);
$result = self::$client->get(["project/{projectId}", ["projectId" => $projectId]]);
我已经检查了 this old documentation and this 个问题,但无法解决。
抛出的异常是:URI 必须是字符串或 UriInterface。
我找不到与 Guzzle 6 相关的任何文档。
Guzzle 的 get
方法定义是 get(string|UriInterface $uri, array $options = [])
并且您将数组作为 $uri
传递,这在此处是不允许的。
你必须自己构建 uri,因为 guzzle 不会为你做那件事。
正确的代码块应该如下所示(如果 projectId
是整数):
$result = self::$client->get(sprintf('project/%d', $projectId));