【发布时间】:2017-01-25 20:31:07
【问题描述】:
我需要将这样的 cURL 命令转换为 Guzzle-way:
curl -XPOST "https://api/v1.0/endpoint" -F "file=@img.jpg"
这是我目前正在尝试的:
$httpClient = new \GuzzleHttp\Client;
$req = $httpClient->createRequest('POST', $url), []);
$postBody = $req->getBody();
$postBody->addFile(new \GuzzleHttp\Post\PostFile('photo', fopen(storage_path() . '/' . $filename, 'r')));
$response = $httpClient->send($req);
但我没有得到与上一个命令相同的响应,类似于:
{"id":5378678,"url":"ui/54/68/97/24/img.jpg"}
我得到一个GuzzleHttp\Message\Response 对象,但我无法在其中找到 id 和 url 属性。
任何帮助将不胜感激!
【问题讨论】:
标签: php curl file-upload guzzle