我想向Guzzle Http請求添加一些數據。有文件名,文件內容和帶有授權密鑰的標題。Guzzle 6發送多部分數據
$this->request = $this->client->request('POST', 'url', [
'multipart' => [
'name' => 'image_file',
'contents' => fopen('http://localhost:8000/vendor/l5-swagger/images/logo_small.png', 'r'),
'headers' =>
['Authorization' => 'Bearer uCMvsgyuYm0idmedWFVUx8DXsN8QzYQj82XDkUTw']
]]);
,但我得到的錯誤
Catchable Fatal Error: Argument 2 passed to GuzzleHttp\Psr7\MultipartStream::addElement() must be of the type array, string given, called in vendor\guzzlehttp\psr7\src\MultipartStream.php on line 70 and defined in vendor\guzzlehttp\psr7\src\MultipartStream.php line 79
在狂飲6文檔是這樣的:http://docs.guzzlephp.org/en/latest/request-options.html#multipart
誰知道我犯了一個錯誤?
有一些例子在這裏:創建與密碼交付式驗證一個symfony的OAuth2用戶API客戶端(http://www.inanzzz.com/index.php/post/l4zx/creating-a-symfony -oauth2-api-client-that-authenticates-with-password-grant-type)和[從另一個應用程序中使用帶有Guzzle客戶端的symfony API](http://www.inanzzz.com/index.php/post/u0xf/使用symfony-api-with-guzzle-client-from-another-application) – BentCoder
但是,這些教程都是以前的Guzzle版本。我正在使用最新版本。 –
第一個鏈接使用guzzle 6 – BentCoder