Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Http 流明$request->;all()返回空数组_Http_Curl_Swagger_Swagger Ui_Lumen - Fatal编程技术网

Http 流明$request->;all()返回空数组

Http 流明$request->;all()返回空数组,http,curl,swagger,swagger-ui,lumen,Http,Curl,Swagger,Swagger Ui,Lumen,我试图从Swagger UI向我的服务器(Lumen)发出POST请求,但每次我都会得到一个空数组 招摇过市用户界面请求: curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \ "stocks":[ \ { \ "contract-number":0, \ "metal-id":0, \ "

我试图从Swagger UI向我的服务器(Lumen)发出POST请求,但每次我都会得到一个空数组

招摇过市用户界面请求:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{   \ 
"stocks":[   \ 
   {   \ 
      "contract-number":0, \ 
      "metal-id":0, \ 
      "amount":0, \ 
      "unit":"string" \ 
   } \ 
] \ 
}' 'http://backend.mywebsite.de/v1/stocks'
我的控制器:

...
public function stocksPost(Request $request)
{
        dd($request->all());
}
...
以及输出:

/var/www/vhosts/localhost/htdocs/vendor/illuminate/support/Debug/Dumper.php:23:
array(0) { }
但如果我向邮递员发送相同的请求,一切都会很好:

    /var/www/vhosts/localhost/htdocs/vendor/illuminate/support/Debug/Dumper.php:23:
array(1) {
  'stocks' =>
  string(68) "[{"contract-number": 0,"metal-id": 0,"amount": 0,"unit": "string"} ]"
}

我不明白我的问题,有人能向我澄清一下吗?

招摇过市请求的问题是它以双引号发送了我的数据,因为它无法验证为JSON,只能从php://input 一串。我只使用自己的curl请求就解决了这个问题,我要么将JSON数据放在单引号中,要么将其作为外部文件附加

curl -X POST -d @foo/bar/contractsPayload.json http://backend.mywebsite.de/v1/stocks -H 'Content-Type: application/json' -H 'Accept:application/json'

打开你的邮递员请求,让它为请求生成代码。选择cURL作为语言,并根据您的炫耀请求验证它