我正在使用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 log的数组它中的线条)。我将如何重构上述内容以便成功推送此数据?
答案 0 :(得分:3)
事实证明,对于大量内容,您应该将有效负载放在:body
而不是:query
。对于遇到此问题的未来人员,正确的代码(使用上述示例)将是:
this_component = {"name" => "something", "ip" => "localhost", "logs" => logs_to_push}
payload = {"body" => {"payload" => JSON.dump(this_component)}}
response = JSONClient.post("http://localhost:8080/log", payload)
答案 1 :(得分:1)
尝试使用后期需求
require 'httparty'
require 'json'
load = {:name => "xyz",:logs => "xyz"}
payload = load.to_json
url="http://xyz.com/abc"
response = HttParty.post(url,{:body => payload})
由于