简体   繁体   English

cURL命令到Guzzle

[英]cURL command to Guzzle

I need to convert a cURL command like this into Guzzle-way: 我需要将这样的cURL命令转换为Guzzle-way:

curl -XPOST "https://api/v1.0/endpoint" -F "file=@img.jpg"

This is what I'm trying so far: 到目前为止,我正在尝试以下操作:

$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);

But I'm not getting the same response as with the previous command, which is something like: 但是我没有得到与先前命令相同的响应,就像这样:

{"id":5378678,"url":"ui/54/68/97/24/img.jpg"}

I'm getting a GuzzleHttp\\Message\\Response object, but I'm not being able to find the id and url attributes in there. 我正在获取GuzzleHttp\\Message\\Response对象,但是无法在其中找到id和url属性。

Any help will be appreciated! 任何帮助将不胜感激!

只是注意到我可以做$response->json()来获得我想要的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM