uzz回流? [英] Guzzle Returning Stream?

查看:95
本文介绍了uzz回流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个:

private function logSearch($term)
    {
        $geo_data = $this->geoIP($ip);
        dd($geo_data);
    }

public function geoIP($ip)
    {
        $url = "http://api.ipstack.com/$ip?access_key=" . env('GEOIP_KEY');    
        $response = $this->client->request('GET', $url);
        return $response->getBody();
    }

响应应为:

{"ip":"78.63.56.237","type":"ipv4","continent_code":"EU"...etc}

但是我却得到了:

Stream {#482
  -stream: stream resource @290
    wrapper_type: "PHP"
    stream_type: "TEMP"
    mode: "w+b"
    unread_bytes: 0
    seekable: true
    uri: "php://temp"
    options: []
  }
  -size: null
  -seekable: true
  -readable: true
  -writable: true
  -uri: "php://temp"
  -customMetadata: []
}

推荐答案

我认为您需要添加getContents().
这个答案对您有用: Guzzlehttp-如何从中获取响应的正文食尸鬼6?
请尝试此代码.

I think you need to add getContents().
This answer would be useful for you: Guzzlehttp - How get the body of a response from Guzzle 6?
Please try this code.

private function logSearch($term)
{
    $geo_data = $this->geoIP($ip);
    dd($geo_data);
}

public function geoIP($ip)
{
    $url = "http://api.ipstack.com/$ip?access_key=" . env('GEOIP_KEY');    
    $response = $this->client->request('GET', $url);
    return $response->getBody()->getContents();
}

这篇关于uzz回流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆