[英]$this->request->getData() empty after upgrade to CakePHP 4.0
[英]$this->request->getData() return inappropriate response in case of post json array in cakephp 3.5
我正在使用cakephp 3.5创建REST API。 当我使用POST MEN工具将数据发布到控制器时,我已经在控制器内部创建了一个控制器和方法。 它给我一个意想不到的回应
以下是我尝试在帖子数据中使用的json数组
{
"type": true,
"userRole": "customer",
"signupType": "test",
"userProfile": {
"email": "admin@test.com",
"password": "YLhdh3UfH/oqppQ/P4wUBw==",
"first_name": "admin",
"last_name": "admin",
"phone_no": "admin",
"profile_image": "test.jpg",
"street_address": "test address",
"state": "Chandigarh",
"city": "Chandigarh",
"zipcode": "160022",
"latitude": "30.723306",
"longitude": "76.766114",
"rating": "5",
"role": "customer",
"status": "1"
}
}
这是我进入内部方法的数据:-
Array
(
[{"type":"true","userRole":"customer","signupType":"gojus","userProfile":{"email":"admin@gojus_com","password":"YLhdh3UfH/oqppQ/P4wUBw] => =","first_name":"admin","last_name":"admin","phone_no":"admin","profile_image":"test.jpg","street_address":"test address","state":"Chandigarh","city":"Chandigarh","zipcode":"160022","latitude":"30.723306","longitude":"76.766114","rating":"5","role":"customer","status":"1"}}
)
这是获取我正在获取“ [{”的数据的问题,我该如何解决cakephp 3.5中的问题
阅读手册: XML或JSON数据
使用REST的应用程序经常在非URL编码的邮件正文中交换数据。 您可以使用Http \\ ServerRequest :: input()读取任何格式的输入数据。 通过提供解码功能,您可以以反序列化格式接收内容:
// Get JSON encoded data submitted to a PUT/POST action
$jsonData = $this->request->input('json_decode');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.