加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – RoR Net :: HTTP post error undefined方法`by

发布时间:2020-12-16 19:24:01 所属栏目:百科 来源:网络整理
导读:我正在反复敲打我的头,直到我通过这个问题.我正在使用 ruby-1.9.3-p194和Rails.我正在尝试发布一个帖子请求,我可以用Net :: HTTP.post_form做得很好,但我不能在这里使用它,因为我需要在标题中设置一个cookie. http.post说错了 "undefined method `bytesize'
我正在反复敲打我的头,直到我通过这个问题.我正在使用 ruby-1.9.3-p194和Rails.我正在尝试发布一个帖子请求,我可以用Net :: HTTP.post_form做得很好,但我不能在这里使用它,因为我需要在标题中设置一个cookie. http.post说错了
"undefined method `bytesize' for #<Hash:0xb1b6c04>"

因为我猜它正试图对正在发送的数据执行一些操作.

有没有人有某种修??复或解决方法?

谢谢

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)

解决方法

bytesize方法是String,而不是Hash.那是你的第一个线索.第二个线索是 Net::HTTP#post的文档:

post(path,data,initheader = nil,dest = nil)

Posts data (must be a String) to path. header must be a Hash like { ‘Accept’ => ‘/’,… }.

你正试图传递哈希,{‘test’=> ‘test’},发布它希望看到字符串的位置.我想你想要更像这样的东西:

http.post(uri.path,'test=test',headers)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读