jjzjj

php - Guzzle 请求查询参数

我有一个使用gullzehttp的方法,我想将它更改为池,并且池实现了Request方法'123456'];$header=['Accept'=>'application/xml'];$options=['query'=>$params,'headers'=>$header];$response=$client->request('GET','http://httpbin.org/get',$options);我需要更改为Request方法,但我在文档中找不到如何在Request中发送查询字符串变量 最佳答案 您需要将查询作为字符串

php - 使用 Guzzle 将文件发布到 Web 服务

我已经尝试了几个小时来发出发送文件的POST请求。首先尝试了一个带有流上下文的简单file_get_contents(),似乎不起作用。当不同URL上的GET有效时,我从未收到回复。我在网上搜索HTTP客户端,发现Guzzle在Packagist上被下载了40万次;我决定尝试这项技术。有据可查,但是,唉,在发布该死的文件时也会出错。$request=$client->post('/files/')->addPostFields(array('comments'=>'novalue'))->addPostFile('file','test.doc')->setAuth($this->us

php - Google REST-ful 调用 + Guzzle : Setting Authorization Token

我是Guzzle的新手,我正在尝试使用它调用GoogleAPI。我以这种方式尝试但没有运气:PHP+Guzzle,SendingAuthorizationKeyinHeader这是我的代码:$client=newClient();try{$request=$client->get('https://www.googleapis.com/analytics/v3/data/ga');/*settingAuthorizationtoken*/$request->addHeader('authorization',$accessToken);$query=$request->getQuery

php - 循环 PHP 嵌套数组 - 将值提取到 Blade Views (Laravel)

我知道有很多关于这个主题的问题,但没有一个能完全解决这个问题(据我所知)。我在Laravel项目中有一个PHP数组(仅供引用,通过Guzzle响应返回)。PHP数组$users=array(2){["error"]=>bool(false)["spirits"]=>array(2){[0]=>array(2){["id"]=>string(1)"1"["name"]=>string(5)"Foo"}[1]=>array(2){["id"]=>string(1)"2"["name"]=>string(3)"Bar"}}}我只是想提取下面的“id”和“name”键,以便在View中使用,但

在Laravel 5中加载带有Guzzle的远程视频

我正在尝试使用Guzzle加载和播放在子域中(subdomain.domain.com)上的远程视频到主域中的位置(domain.com)。我发现很难播放视频。刀片文件中的视频播放器具有以下视频源的URL`....`源的路线导致具有以下代码的控制器'http://subdomain.domain.com/api/']);$resp=$client->request('GET',"video/".$videoname,['stream'=>true]);$body=$resp->getBody();echo$body;}}亚域APIMethos如下:file(storage_path("app/

使用guzzle中的邮政请求中传递阵列

我正在尝试通过邮政请求有效载荷传递数组。url=http://IP:PortNo/index.php/v1/login有效载荷:data={"terminal_id":"terminal_id","api_login":"api_login","api_key":"api_key","merchant_code":"merchant_code"}我所做的是:$data=['terminal_id'=>$this->terminal_id,'api_login'=>$this->api_login,'api_key'=>$this->api_key,'merchant_code'=>$this-

php - 使用 PHPUnit 在 Laravel Controller 内部进行单元测试 Guzzle

我不太确定在这种情况下采用哪种方法进行单元测试。单元测试Guzzle的所有示例对我如何在这种情况下实现都不太有意义,或者我可能只是错误地看待它。设置:Laravel4.2RESTAPI-Controller方法在方法中使用Guzzle从另一个API请求数据,如下所示:request('POST',$url,['body'=>array(...)]);//Morestuff}}?>我认为我可以按如下方式进行单元测试,一切都会正常进行。functiontestGetAllWidgets(){$mock_response=array('foo'=>'bar');$mock=newMockHa

php - Guzzle Curl 错误未被 try catch 语句捕获(Laravel)

在Laravel项目中,我需要调用APIREST来删除远程数据。我的问题是当我遇到错误时,我的catch语句没有捕获Guzzle异常。我的代码如下:try{$client=new\GuzzleHttp\Client();$request=$client->delete(Config::get('REST_API').'/order-product/'.$id);$status=$request->getStatusCode();}catch(Exception$e){var_dump($e);exit();}异常被Laravel捕获,但没有在我的catch语句中。Guzzle抛出的异常

php - Laravel guzzle cURL 错误 6 : Could not resolve host: http (see http://curl. haxx.se/libcurl/c/libcurl-errors.html)

在我的开发过程中,我的代码运行正常。当我推送到我的服务器时,它变成了错误。cURL错误6:无法解析主机:http(请参阅http://curl.haxx.se/libcurl/c/libcurl-errors.html)这是我的代码:useGuzzleHttp\Client;try{$client=newClient();$client->request('POST',env('API_DOMAIN').'/v1/user/auth/verified_email',['headers'=>['Authorization'=>'cm9vcGlhLnVzZXIud2ViOkY0RVN3VX

php - POST 请求适用于 Postman,但不适用于 Guzzle

在我的Laravel应用程序中,我需要定期使用Guzzle将数据发布到API。API使用不记名token进行身份验证,请求并接受原始json。为了进行测试,我使用Postman访问了API,一切都运行良好。postman标题:Accept:application/jsonAuthorization:Bearer[token]Content-Type:application/json和Postman主体:{"request1":"123456789","request2":"2468","request3":"987654321","name":"JohnDoe"}Postman返回一个