ruby httparty在帖子后获得响应url或id

如何在发布帖子后在单独的脚本中使用httparty从rails项目获取响应URL或ID? 红宝石脚本:
  HTTParty.post('http://localhost:3000/change_logs', parameters)
response.body和所有其他人不显示网址和响应ID     
已邀请:
两年后,我找到了一种方法来访问
response
request
属性的最后一个URI:
url      = "http://example.com/redirects/to/www"
response = HTTParty.get(url)
response.request.last_uri.to_s
# => "http://www.example.com"
    
不幸的是,HTTParty没有保留这些信息。当遇到重定向时,它将遵循重定向并返回该请求的结果。它不会保存原始请求中的任何信息。 好消息是,这样的行为(通常)是可预测的。在对URL发布请求后,Web应用程序通常会重定向到相同的内容。 但是如果你真的想这样做,你将不得不使用Ruby附带的net / http库。然而,它并不比HTTParty难得多,所以它不是更多的工作。     
这对我有用,可能有更好的方法来做到这一点..
get_change_log_id = HTTParty.post('http://localhost:3000/change_logs.xml', parameters).to_a

get_change_log_id.each do |r|
  r.each do |sub|
    sub2 = sub.to_a
      sub2.each do |s|
        if s.index "id"
          @change_log_id = s.to_s.sub(/[i]/, '').sub(/[d]/, '')
        end
      end
  end
end
    

要回复问题请先登录注册