I am currently banging my head against the wall repeatedly until I get passed this issue. I'm using ruby-1.9.3-p194 and Rails. I'm attempting to make a post request which I can do fine with Net::HTTP.post_form, but I can't use that here because I need to set a cookie in the header. http.post is erroring saying
"undefined method `bytesize' for #<Hash:0xb1b6c04>"
because I guess it's trying to perform some operation on the data being sent.
Does anyone have some kind of fix or work around?
Thanks
headers = {'Cookie' => 'mycookieinformationinhere'}
uri = URI.parse("http://asite.com/where/I/want/to/go")
http = Net::HTTP.new(uri.host, uri.port)
response = http.post(uri.path, {'test' => 'test'}, headers)
The bytesize
method is on String
, not Hash
. That's your first clue. The second clue is the documentation for Net::HTTP#post
:
post(path, data, initheader = nil, dest = nil)
Posts
data
(must be a String) topath
.header
must be a Hash like { ‘Accept’ => ‘/’, … }.
You're trying to pass a Hash, {'test' => 'test'}
, to post
where it expects to see a String
. I think you want something more like this:
http.post(uri.path, 'test=test', headers)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With