gpt4 book ai didi

ruby-on-rails - RestClient::Request.execute传递哈希集

转载 作者:行者123 更新时间:2023-12-04 10:01:07 27 4
gpt4 key购买 nike

我一直在这样使用RestClient请求:

response = RestClient.post server_url, post_params, accept: :json

一直很好。但是我需要增加超时时间,因为它有时并不会在服务器执行上载时完成。

我研究发现,唯一的解决方案是将语法更改为:
response = RestClient::Request.execute(:method => :post, :url => server_url, post_params, :timeout => 9000000000)

但是,我似乎无法像上次调用中那样传递参数的哈希图( 'post_params')。我应该如何编写请求,以便包括 'post_params'。这是一个复杂的哈希图,因此我无法对其进行扩充或摆脱它。

非常感谢您的帮助。

最佳答案

您发送的数据称为有效负载,因此您需要将其指定为有效负载:

response = RestClient::Request.execute(:method => :post, :url => server_url, :payload => post_params, :timeout => 9000000, :headers => {:accept => :json})

另外,您可能希望使用较短的超时,否则可能会收到Errno::EINVAL:无效的参数。

关于ruby-on-rails - RestClient::Request.execute传递哈希集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14596773/

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