Last active
January 7, 2016 15:18
-
-
Save matt-allan/e6505f54fe6fd6117030 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$stream = new GuzzleHttp\Psr7\MultipartStream([['name' => 'some-file', 'contents' => 'the contents']]); | |
$client = new GuzzleHttp\Client(); | |
$r = $client->request('POST', 'http://httpbin.org/post', ['body' => $stream]); | |
$r->getBody()->getContents(); | |
=> """ | |
{\n | |
"args": {}, \n | |
"data": "", \n | |
"files": {}, \n | |
"form": {\n | |
"some-file": "the contents"\n | |
}, \n | |
"headers": {\n | |
"Content-Length": "122", \n | |
"Content-Type": "multipart/form-data; boundary=568daeba8d610", \n | |
"Host": "httpbin.org", \n | |
"User-Agent": "GuzzleHttp/6.1.1 curl/7.37.1 PHP/5.6.13"\n | |
}, \n | |
"json": null, \n | |
"origin": "72.18.228.42", \n | |
"url": "http://httpbin.org/post"\n | |
}\n | |
""" | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What I don't understand, is how your Content-Type is being set by Guzzle. I am finding Guzzle, using PSR-7 messages does not detect the content type automatically, and does not set the Content-Type header. I am having to explicitly set the
Content-Type
header, which means also defining my own multipart boundary for this (Guzzle can give you the boundary it defines, but that is less portable). Are you using a stable Guzzle, or bleeding-edge dev?