本文介绍了精简版客户端在laravel中引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在laravel中发出一个http发帖请求

I am trying to make a http post request in laravel as below

$client = new Client(['debug'=>true,'exceptions'=>false]);
  $res = $client->request('POST', 'http://www.myservice.com/find_provider.php',  [
            'form_params' => [
                'street'=> 'test',
                'apt'=> '',
                'zip'=> 'test',
                'phone'=> 'test',
            ]
        ]);

返回空响应.调试时,发生以下异常

It return empty response. On debugging ,following exception is occurring

curl_setopt_array():不能将输出类型的流表示为STDIO FILE *

curl_setopt_array(): cannot represent a stream of type Output as a STDIO FILE*

我正在使用最新版本的guzzle.

I am using latest version of guzzle.

有什么想法要解决吗?.

Any idea how to solve it?.

推荐答案

request()方法将返回 GuzzleHttp \ Psr7 \ Response 对象.要获取服务返回的实际数据,您应该使用:

The request() method is returning a GuzzleHttp\Psr7\Response object.To get the actual data that is returned by your service you should use:

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

现在检查$ data中的内容以及它是否与预期的输出相对应.

Now check what you have in $data and if it corresponds to the expected output.

有关在此处使用Guzzle响应对象的更多信息

这篇关于精简版客户端在laravel中引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 04:54