duanqiang3925 2018-01-02 14:17
浏览 526
已采纳

laravel API调用中的Guzzle HTTP不返回预期的响应

I'm attempting a GET request to acquire an email_token with Guzzle HTTP that looks like this:

$email = $customer['attributes']['Email'];

    $client = new Client();
    $res = $client->request('GET', 'https://www.example.com/apps/api/Services/Email/Opting', [
        'email' => $email
    ]);
    dd($res->getBody());

The response is returning 200/OK, but I'm not getting the email_token as expected. The sparse API docs I'm working off give a very similar example and state the expected response's content should look something like this:

{
    "email": "test@example.com",
    "marketing": true,
    "promotional": true,
    "news": true,
    "feedback": true,
    "account_related": true,
    "token": "eyJpdiI6Ik9tNlFwbEorbjNnK1FsNnFZb1ZtaFE9PSIsInZhbHVlIjoibGNheWpDR0Z6eWpcL1VCbjdsUXZCS0lzRURBZTIzMVc5ZXRTamQrd1dQTFE9IiwibWFjIjoiYTEwYTM2ODU0MmQzMTY5NGIwNWFhOWFjM2ZiZTBkMzkzOWMyY2VkYTMzNjk5ZDYyOTE0OGY2YjBhNGNkYjk4NyJ9"
}

Once I get the token, I then need to make a POST with a couple more requirements (one being the email_token) in order to automate a customer's ability to opt out of the mailing list. Any thoughts on why my response is coming back like this?

Screenshot of dd($res);

Screenshot of dd($res->getBody());

  • 写回答

1条回答 默认 最新

  • duanchen7703 2018-01-02 14:25
    关注

    In order to get the response payload you should do:

    $response = $res->getBody()->getContents();
    

    To get the status:

    $responseStatus = $res->getStatusCode();
    

    documentation for more: Guzzle

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图