我有这个qazxsw poi命令,我需要转换为PUT请求
curl
我尝试了这个PUT,但它不起作用。它不会抛出任何错误,但它不会添加描述。
curl https://example.com/api/v2/students/id.json \
-d '{"student":{"description":{"body":"Adding a new test description"}}}' \
-H "Content-Type: application/json" \
-v -u [email protected]:Abcd1234 \
-X PUT
在curl示例中,您将主体提供为(JSON格式的)字符串:
put(
"https://example.com/api/v2/students/id.json",
{:student => {:description => {:body => 'Adding a new test description.'}}},
{ 'Authorization' => "Basic #{authorization_token}" }
)
rest-client中的直接等价物也将使用(JSON格式)字符串:
curl ... \
-d '{"student":{"description":{"body":"Adding a new test description"}}}' \
...
根据put( ...,
'{"student":{"description":{"body":"Adding a new test description"}}}',
...
)
:
rest-client本身不会说JSON,因此在将有效负载传递给rest-client之前将其序列化为字符串。
您可以使用rest-client日志显示发送的实际HTTP请求,并将其与curl发送的内容进行比较。
How to display request headers with command line curl
使用
curl https://example.com/api/v2/students/id.json \
-d '{"student":{"description":{"body":"Adding a new test description"}}}' \
-H "Content-Type: application/json" \
-v -u [email protected]:Abcd1234 \
-X PUT