http-client 如何发送json及二进制图片 各种方式都试了, 不得行
<?php use Workerman\Worker; require_once 'vendor/autoload.php'; $worker = new Worker(); $worker->onWorkerStart = function () { $http = new Workerman\Http\Client(); // 上传文件 $multipart = new \Workerman\Psr7\MultipartStream([ [ 'name' => 'file', 'contents' => fopen(__FILE__, 'r') ], [ 'name' => 'json', 'contents' => json_encode(['a'=>1, 'b'=>2]) ] ]); $boundary = $multipart->getBoundary(); $http->request('http://127.0.0.1:8787', [ 'method' => 'POST', 'version' => '1.1', 'headers' => ['Connection' => 'keep-alive', 'Content-Type' => "multipart/form-data; boundary=$boundary"], 'data' => $multipart, 'success' => function ($response) { echo $response->getBody(); }, 'error' => function ($exception) { echo $exception; } ]); }; Worker::runAll();
类似这样上传文件
好的,老大, 感谢回复
类似这样上传文件
好的,老大, 感谢回复