我正在尝试获取之前有效的http帖子请求,但我再次工作了。
def post_params
uri = Addressable::URI.new
uri.query_values = {
from: @from_city_id,
to: @to_city_id,
tmp_from: @from_city,
tmp_to: @to_city,
date: @when_date.strftime('%d.%m.%Y')
}
uri.query
end
http = Net::HTTP.new "www.domain.com"
res = http.post '/', post_params
raise res.inspect
但我最终遇到文件结束错误。 还有一件事:我不打算进行https查询。
感谢您的帮助
答案 0 :(得分:2)
我最终发现,问题是我需要指定一个cookie,否则我会收到“文件结束”错误。
http = Net::HTTP.new "www.domain.com"
http.use_ssl = false
res_get = http.request(Net::HTTP::Get.new('/'))
cookie = res_get.response['set-cookie']
request = Net::HTTP::Post.new '/'
request.set_form_data post_params
request["Cookie"] = cookie
res = http.request(request)