我正在尝试使用 HTTPie 测试我的 Rails 5 API 端点。我在终端中运行的命令是:
http POST :3000/users email=test@example.com password=anewpassword password_confirmation=anewpassword
我得到的回应是:
HTTP/1.1 400 Bad Request
Cache-Control: no-cache
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Request-Id: c3ca4d50-9501-46e9-a7e1-a4576d6cdd7e
X-Runtime: 0.010404
X-XSS-Protection: 1; mode=block
{
"errors": [
"Password can't be blank"
]
}
这意味着它违背了我的验证。但是,据我所知,它不应该是。这是我从 Rails 服务器终端得到的:
Started POST "/users" for 127.0.0.1 at 2017-02-03 12:09:54 -0800
Processing by UsersController#create as JSON
Parameters: {"email"=>"test@example.com", "password"=>"[FILTERED]",
"password_confirmation"=>"[FILTERED]", "user"=>{"email"=>"test@example.com"}}
(0.1ms) BEGIN User Exists (0.4ms) SELECT 1 AS one FROM "users"
WHERE LOWER("users"."email") = LOWER($1) LIMIT $2 [["email","test@example.com"], ["LIMIT", 1]]
(0.1ms) ROLLBACK
Completed 400 Bad Request in 3ms (Views: 0.1ms | ActiveRecord: 0.6ms)
关于我做错了什么的任何想法?我感觉我没有正确使用 HTTPie,但是我的 Google-fu 找不到太多。
编辑
我可以确认路线有效。使用 Postman 并在请求正文中传递以下 JSON 可以获得预期的响应:
{"user": {"email": "test@example.com","password": "anewpassword","password_confirmation": "anewpassword"}}
Response:
{"status": "User created successfully"}