相关文章推荐

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account 'name' => 'file',
'filename' => $file->getClientFilename(),
'contents' => fopen($file->getRealPath(), 'r')
$options = [
'base_uri' => "",
'timeout' => 60,
'headers' => [
'X-AUTH-TOKEN' => ‘',
'Content-Type' => 'multipart/form-data',
"Accept: application/json"
'form-data' => $form_data,
'multipart' => $multipart
服务器端:
$file = $this->request->file("file");
$subject = $this->request->post("subject");
$paper_id = $this->request->post("paper_id", 0);
$manager_id = $this->request->post("manager_id", 0);
logger()->debug(print_r($this->request->getBody()->getContents(), true));
所有解析参数都为空,但是getBody实际上已可以获取到所有参数及文件

Steps To Reproduce:

$ client = new Client ([ 'handler' => di()-> get ( HandlerStackFactory ::class)-> create (), 'base_uri' => 'http://127.0.0.1:9501' , $ response = $ client -> post ( '/http/file' , [ 'query' => [ 'id' => 1 , 'name' => uniqid(), 'Content-Type' => 'multipart/form-data' , 'multipart' => $ multipart ,

https://github.com/limingxinleo/hyperf-demo/tree/http

$ curl http://127.0.0.1:9501/http/upload                                                                                                                                                                                                      

你自己试试吧,我这边测试时可以的。。

query 参数相当于把参数放到了 uri 上。

'name' => 'file',
'filename' => $file->getClientFilename(),
'contents' => fopen($file->getRealPath(), 'r')
'name' => 'paper_id',
'contents' => 5899
'name' => 'subject',
'contents' => '数学'
'name' => 'manager_id',
'contents' => 1
$options = [
'base_uri' => "",
'timeout' => 60,
'headers' => [
'X-AUTH-TOKEN' => '',
'Content-Type' => 'multipart/form-data',
"Accept: application/json"
'multipart' => $data,
$client = new Client([ 'handler' => di()->get(HandlerStackFactory::class)->create(), 'base_uri' => 'http://127.0.0.1:9501', $response = $client->post('/http/file', [ 'multipart' => $multipart, return $response->getBody()->getContents();

代码我改了下,你这样试试,我这边可以的。guzzle 是可以自动解析的

 
推荐文章