1

I'm trying to get an http post request that worked before but anymore to work again.

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

But I end up having a End of file error. One more thing: I'm not trying to make a https query.

Thanks for your help

m0g
  • 115
  • 1
  • 14
  • is the request using ssl now? have a look at this [link](http://stackoverflow.com/questions/5244887/eoferror-end-of-file-reached-issue-with-nethttp?rq=1) – danmanstx Aug 28 '13 at 18:19
  • We can't duplicate the problem given the code you supplied. We need more information. See http://sscce.org/ – the Tin Man Aug 29 '13 at 04:10

1 Answers1

3

I eventually find out, the problem was that I needed to specify a cookie otherwise I would get the "end of file" error.

    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)
m0g
  • 115
  • 1
  • 14