gpt4 book ai didi

带有负载的 Ruby RestClient GET 请求

转载 作者:数据小太阳 更新时间:2023-10-29 08:29:59 26 4
gpt4 key购买 nike

请帮我解决以下问题:我有很多申请和相关记录。

app with id 1 has: record1, record2 and record3.
app with id 2 has: record1 ... record1000

要使用 curl 过滤掉应用程序 1 的记录。我可以使用以下命令获取记录:

curl -i -H "accept: application/json" -H "Content-type: application/json"  -X GET -d '{ "filters": { "app_id":"1" }}' http://[rails_host]/v1/records?token=[api_token]

除了使用 ruby​​ RestClient (gem 'rest-client' '1.7.2'),我该怎么做呢

要获取所有记录,我执行以下操作:

RestClient.get("http://[rails_host]/v1/records?token=[api_token]", { :content_type => 'application/json', :accept => 'application/json'})

问题是没有返回应用程序 ID,所以我无法解析响应并获取应用程序 ID = 1 的记录

关于如何将负载添加到 Restclient.get 以过滤掉记录的任何想法?

最佳答案

您可以在文档中看到 here唯一接受有效负载参数的高级助手是 POST、PATCH 和 PUT。要使用负载发出 GET 请求,您需要使用 RestClient::Request.execute

这看起来像:

RestClient::Request.execute(
method: :get,
url: "http://[rails_host]/v1/records?token=[api_token]",
payload: '{ "filters": { "app_id":"1" } }',
headers: { content_type: 'application/json', accept: 'application/json'}
)

关于带有负载的 Ruby RestClient GET 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46381435/

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