【发布时间】:2016-06-13 11:56:52
【问题描述】:
当我在http://www.yiiframework.com/doc-2.0/guide-rest-quick-start.html中使用命令时:
curl -i -H "Accept:application/json" -H "Content-Type:application/json" -XPOST "my api path/users" -d '{"username": "testuser", "email": "user@123.com"}'
它返回:
HTTP/1.1 400 Bad Request
Date: Tue, 01 Mar 2016 06:51:03 GMT
Server: Apache/2.4.4 (Win32) PHP/5.6.9
X-Powered-By: PHP/5.6.9
Vary: Accept-Encoding
Content-Length: 148
Connection: close
Content-Type: application/json; charset=UTF-8
{"name":"Bad Request","message":"Invalid JSON data in request body: Syntax error
.","code":0,"status":400,"type":"yii\\web\\BadRequestHttpException"}curl: (6) Co
uld not resolve host: testuser,
curl: (6) Could not resolve host: email
curl: (3) [globbing] unmatched close brace/bracket at pos 13
【问题讨论】:
-
尝试删除 JSON 中的空格。
-
您也可以将 JSON 放入文件并在
cURL中使用--data @data.json发送 -
"my api path/users"您使用的是url路径,而不是包含应用程序的文件夹的路径,对吧?