使用 HTTParty 发布大量数据
我使用 HTTParty 使用以下代码将信息发布到服务器:
this_component = {"name" => "something", "ip" => "localhost", "logs" => logs_to_push}
payload = {"payload" => JSON.dump(this_component)}
response = JSONClient.post("http://localhost:8080/log", :body => '', :query => payload)
问题是,当 POST 实际执行时,我收到一条 Connection Reset by Peer (Errno::ECONNRESET)
消息,我'我很确定这是由于我的有效负载太大造成的(因为 logs_to_push
是一个包含约 200 条日志行的数组)。我如何重构上述内容才能成功推送这些数据?
I'm using HTTParty to post information to a server using the following code:
this_component = {"name" => "something", "ip" => "localhost", "logs" => logs_to_push}
payload = {"payload" => JSON.dump(this_component)}
response = JSONClient.post("http://localhost:8080/log", :body => '', :query => payload)
The problem is that I get a Connection reset by peer (Errno::ECONNRESET)
message when the POST actually executes, which I'm pretty sure is caused by my payload being too large (as logs_to_push
is an array with ~200 log lines in it). How would I refactor the above so that I could push this data successfully?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,事实证明,对于大量内容,您应该将有效负载放入
:body
而不是:query
中。对于将来遇到此问题的人,正确的代码(处理上面的示例)将是:So it turns out that for large amount of stuff, you should put the payload in
:body
and not:query
. For future people that run into this problem, the correct code (working off the above example) would be:尝试这个帖子请求
谢谢
Try This for Post Req
Thanks