From e6e668ebecaf1c4661b05c8708db320d7dd13e57 Mon Sep 17 00:00:00 2001 From: minchao Date: Sat, 2 Apr 2022 17:00:52 +0800 Subject: [PATCH] fix: guzzle MalformedUriException --- src/Client.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index 7f55e62..6feec3f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -26,6 +26,7 @@ use function getenv; use function json_encode; use function time; +use function substr; /** * @property Nodes\Item\Item $item @@ -224,12 +225,16 @@ public function newRequest($uri, array $headers = [], $data = []): RequestInterf $uri = Utils::uriFor($uri); $path = $this->baseUrl->getPath() . $uri->getPath(); + if (substr($path, 0, 1) !== '/') { + $path = '/' . $path; + } + $uri = $uri->withPath($path); + $uri = $uri ->withScheme($this->baseUrl->getScheme()) ->withUserInfo($this->baseUrl->getUserInfo()) ->withHost($this->baseUrl->getHost()) - ->withPort($this->baseUrl->getPort()) - ->withPath($path); + ->withPort($this->baseUrl->getPort()); $jsonBody = $this->createJsonBody($data);