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;        
    

      

  • 相关阅读:
    DOS命令行
    很好的GDAL初学者资料
    VC++工程文件
    C#操作word文档
    vue 如何不复用组件的 DOM All In One
    2021 最新 XBOX 打丧尸游戏 All In One
    gti gc All In One
    custom height drawer All In One
    Redux & React Hooks All In One
    StackOverflow sites All In One
  • 原文地址:https://www.cnblogs.com/blog-dyn/p/13494993.html
Copyright © 2011-2022 走看看