【问题标题】:cURL command to Guzzle用于 Guzzle 的 cURL 命令
【发布时间】: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


    【解决方案1】:

    刚刚注意到我可以通过$response->json() 得到我想要的东西。

    【讨论】:

      猜你喜欢
      • 2020-10-06
      • 2022-07-29
      • 1970-01-01
      • 2020-05-01
      • 2021-05-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      相关资源
      最近更新 更多