【问题标题】:Laravel guzzle httpLaravel 贪吃 http
【发布时间】:2018-12-18 19:28:18
【问题描述】:

谁能用 GuzzleHttp 解决这个问题?我想在控制器中显示 $reportid,但我现在卡住了。

//Select Data For SDO Homepage Report
public function SDOHomepage(){
    $client = new \GuzzleHttp\Client();
    $url=WEBSERVICE_URL;
    //Response 1
    $response1=$client->request('POST', $url,['form_params'=>['tag'=>'selectSDOHomepage']]);

    //$body = $response1->getBody();
    //$reportid = $body['ReportID'];

    //Response 2
    $response2=$client->request('POST', $url,['form_params'=>['tag'=>'sdoCountReply','ReportID'=>$reportid]]);

    $data1=json_decode($response1->getBody()->getContents(),true);
    $data2=json_decode($response2->getBody()->getContents(),true);

    //Return Data
    return view('SDOHomepage',['SDO_All'=>$data1,'SDO_Reply_Count'=>$data2]);   
}

【问题讨论】:

  • 到底出了什么问题?你的控制器在哪里?

标签: php laravel guzzle


【解决方案1】:

你可能错过了这个吗?

$body = $response1->getBody();
$reportid = $body['ReportID'];

您可能需要也可能不需要执行 json_decode 之类的其他操作。

【讨论】:

  • 感谢您的回答。但我有一个错误提示(不能使用 GuzzleHttp\Psr7\Stream 类型的对象作为数组)也许我应该在这里使用另一种方法?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多