composer require guzzlehttp/guzzle:~7.0
use GuzzleHttp\Client; $client=new Client(['timeout' => 5, 'verify' => false]);
use GuzzleHttp\Client; $client=new Client(['timeout' => 5, 'verify' => false]); //设置headers头 $headers=['Content-Type'=>"application/json"]; $url='https://api.netease.im/nimserver/history/queryMediaFileByChannelId.action'; $response=$client->get($url,[ 'headers'=>$headers, ]); //获取http响应 $response->getStatusCode() //获取body找那个返回值信息 json_decode($response->getBody(),true); //获取响应头信息 $response->getHeaders()
use GuzzleHttp\Client; $client=new Client(['timeout' => 5, 'verify' => false]); //设置headers头 $headers=['Content-Type'=>"application/json"];//json $url='https://api.netease.im/nimserver/history/queryMediaFileByChannelId.action'; $body=[ "namae"=>'zhou', "mode"=>2, "uid"=>1, ]; $response=$client->post($url,[ 'headers'=>$headers, 'json'=>$body//发送body为josn格式 ]); //获取http响应 $response->getStatusCode() //获取body找那个返回值信息 json_decode($response->getBody(),true); //获取响应头信息 $response->getHeaders()
use GuzzleHttp\Client; $client=new Client(['timeout' => 5, 'verify' => false]); //设置headers头 $headers=['Content-Type'=>"application/x-www-form-urlencoded"]; $url='https://api.netease.im/nimserver/history/queryMediaFileByChannelId.action'; $body=[ "namae"=>'zhou', "mode"=>2, "uid"=>1, ]; $response=$client->post($url,[ 'headers'=>$headers, 'form_params'=>$body ]); //获取http响应 $response->getStatusCode() //获取body找那个返回值信息 json_decode($response->getBody(),true); //获取响应头信息 $response->getHeaders()
use GuzzleHttp\Client; $headers=['Content-Type'=>"application/json"]; $client=new Client(['timeout' => 5, 'verify' => false]); $response=$client->delete($url,[ 'headers'=>$headers, ]); $code=$response->getStatusCode();、
到此这篇关于php使用GuzzleHttp实现HTTP请求的文章就介绍到这了,更多相关php GuzzleHttp实现HTTP请求内容请搜索插件窝以前的文章或继续浏览下面的相关文章希望大家以后多多支持插件窝!