【发布时间】:2020-12-14 11:02:02
【问题描述】:
我必须在 rails 6 中提出这个请求:
curl --location --request POST 'https://www.example.com/auth' \
--header 'Content-Type: application/json' \
--data-raw '{
"Username": "my_username",
"Password": "my_password"
}'
我们通常使用 HTTParty 发出 http 请求,但我在尝试将原始数据传递到请求中时遇到了一些问题。 我已经试过了:
url = 'https://www.example.com/auth'
auth_data = { Username: 'my_username', Password: 'my_password' }
headers = {'Content-Type' => 'application/json'}
HTTParty.post(url, data: auth_data, headers: headers)
HTTParty.post(url, data: auth_data.to_json, headers: headers)
HTTParty.post(url, data: [auth_data].to_json, headers: headers)
HTTParty.post(url, body: auth_data, headers: headers)
在所有情况下,响应都表示没有传递任何数据
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-6 httparty