zoukankan      html  css  js  c++  java
  • php 使用GuzzleHttp请求接口,传输文件buffer

    你可以使用composer.phar客户端将Guzzle作为依赖添加到项目:

    php composer.phar require guzzlehttp/guzzle:~6.0
    

      或者,你可以编辑项目中已存在的composer.json文件,添加Guzzle作为依赖:

    {
       "require": {
          "guzzlehttp/guzzle": "~6.0"
       }
    }
    

      安装完毕后,你需要引入Composer的自动加载文件:

    require 'vendor/autoload.php';
    
            $filePath=BASE_PATH.'/storage/file/1.jpg';
            $request='{"requestId":"zzsc20200812000000","platformCode":"10012935181","billAccount":"test3485_003@163.com","buffer":"jpg","fileName":"test.jpg"}';
            $request=json_decode($request,true);
            $buffer=readfile($filePath);//文件buffer
            $request['buffer']=base64_encode($buffer);
            $url='http://192.168.1.130:9501/fileUpload/test';
            $headers = [
                "X-99Bill-PlatformCode:10012935181"
            ];
            $body=['headers'=>$headers,'json'=>$request];    
          $options = [];
            // $client 为协程化的 GuzzleHttpClient 对象
            $clientFactory=container()->get(ClientFactory::class);
            $client = $clientFactory->create($options);
      
            $response = $client->request($method,$url,$body);
            // $code = $response->getStatusCode(); // 200
            // $reason = $response->getReasonPhrase(); // OK
            $body = $response->getBody();
            $responseContents = $body->getContents();
            return $responseContents;        
    

      

  • 相关阅读:
    pixijs设置层级的方法
    6.Linux CPU实时监控mpstat命令详解
    5.Linux vmstat命令详解
    4.Linux iostat命令详解
    3.linux top 命令详解
    2.linux sort 命令详解
    1.Linux vim命令详解
    0.Linux命令参考博客
    洛谷 U140956 新漂亮国大选
    CF457C Elections
  • 原文地址:https://www.cnblogs.com/blog-dyn/p/13494993.html
Copyright © 2011-2022 走看看