-H "X-Parse-REST--6ren">
gpt4 book ai didi

ruby - 如何在 Ruby 中编写 CURL PUT 脚本?

转载 作者:太空宇宙 更新时间:2023-11-03 16:02:11 25 4
gpt4 key购买 nike

我有以下代码,如果我在终端中一次输入一行,它运行良好:

curl -X PUT \
> -H "X-Parse-Application-Id: APPID" \
> -H "X-Parse-REST-API-Key: APIKEY" \
> -H "Content-Type: application/json" \
> -d '{"production":true}' \
> https://api.parse.com/1/classes/FIELD/OBJECTID

我如何将其转换为 Ruby 脚本?

我试过使用 httparty、uri、net/http,但 curl 的语法(\'s 和它是一个 PUT 请求的事实)让我感到困惑。

最佳答案

Curb是一个 cURL 包装器。这是一些未经测试的代码:

require 'curb'

# curl -X PUT \
# > -H "X-Parse-Application-Id: APPID" \
# > -H "X-Parse-REST-API-Key: APIKEY" \
# > -H "Content-Type: application/json" \
# > -d '{"production":true}' \
# > https://api.parse.com/1/classes/FIELD/OBJECTID

http = Curl.put("https://api.parse.com/1/classes/FIELD/OBJECTID") do |http|
http.headers['X-Parse-Application-Id'] = 'APPID'
http.headers['X-Parse-REST-API-Key'] = 'APIKEY'
http.headers['Content-Type'] = 'application/json'
http.data = '{"production":true}'
end
puts http.body_str

关于ruby - 如何在 Ruby 中编写 CURL PUT 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21959358/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com