【发布时间】:2019-08-11 09:50:45
【问题描述】:
RestClient 发布请求
我尝试了几种发布请求的方式
@user = {name: 'xxxxxx', email: 'xxxxxx@gmail.com', password: 'qwertyqqq'}
RestClient.post 'http://localhost:4123/api/users?token=<token>', @user
RestClient::Request.execute(method: :post, url: 'http://localhost:4123/api/v1/users', token: '<token>', payload: '@user', headers: {"Content-Type" => "application/json"})
错误:RestClient::BadRequest: 400 Bad Request 或 RestClient::UnprocessableEntity: 422 Unprocessable Entity
成功案例
当我使用 rest 客户端和 curl 发出 get 请求时就可以了。
RestClient.get 'http://localhost:4123/api/v1/users?token=<token>'
使用卷曲:
获取请求:
curl -X GET http://localhost:4123/api/v1/users/1?token=<token>
发帖求助:
curl -d '{"name":"xxxx","email":"xxxx@gmail.com","password":"12345678", "admin": true, "role":"admin"}' -H "Content-Type: application/json" -X POST http://localhost:4123/api/v1/users?token=<token>
【问题讨论】:
标签: ruby rest ruby-on-rails-5 rest-client