【问题标题】:Getting Response from DSTK (Data Science Toolkit) with Guzzle / Goutte使用 Guzzle / Goutte 从 DSTK(数据科学工具包)获得响应
【发布时间】:2016-03-10 18:11:43
【问题描述】:

我正在尝试从数据科学工具包中取回 JSON 数据,但我得到的响应没有。我正在尝试将字符串对象(从地址数组编码的 json)传递给 dstk 字段,以返回坐标列表。

下面是sn-p的代码:

$client = new \GuzzleHttp\Client(['base_uri' => 'http://www.datasciencetoolkit.org/']);
$request = $client->post('street2coordinates', ['form_params' => ['body' => json_encode($addresses)] ]);

当我死的时候转储 dd($request->getBody()),它只返回 ff 对象。甚至只是 $request,我无法在搜索中提取 json 数据我期待纬度/经度坐标 - 但我不知道如何/从哪里获取它们。

object(GuzzleHttp\Psr7\Stream)[215]
  private 'stream' => resource(8, stream)
  private 'size' => null
  private 'seekable' => boolean true
  private 'readable' => boolean true
  private 'writable' => boolean true
  private 'uri' => string 'php://temp' (length=10)
  private 'customMetadata' => 
    array (size=0)
      empty

我也尝试过使用 Goutte 客户端,但无济于事。即使尝试不同的方法,如 ->json() 或 ->toJson(),也没有骰子。帮助表示赞赏。谢谢!

【问题讨论】:

  • 如果在您的客户端中添加选项 'debug' => true 会发生什么?我知道每当我尝试从 datasciencetoolkit.org 域访问任何内容时,都会收到连接重置错误。

标签: php json guzzle goutte


【解决方案1】:

您必须将正文强制为字符串,例如通过回显它或显式转换它。

echo $response->getBody();

或者

dd((string)$response->getBody());

【讨论】:

    猜你喜欢
    • 2014-03-25
    • 2017-10-25
    • 1970-01-01
    • 1970-01-01
    • 2018-05-29
    • 1970-01-01
    • 1970-01-01
    • 2020-09-28
    • 2017-10-24
    相关资源
    最近更新 更多