Ruby - net/http - following redirects

后端 未结 6 1049
北恋
北恋 2020-12-01 03:05

I\'ve got a URL and I\'m using HTTP GET to pass a query along to a page. What happens with the most recent flavor (in net/http) is that the script doesn\'t go

6条回答
  •  天命终不由人
    2020-12-01 03:20

    Maybe you can use curb-fu gem here https://github.com/gdi/curb-fu the only thing is some extra code to make it follow redirect. I've used the following before. Hope it helps.

    require 'rubygems'
    require 'curb-fu'
    
    module CurbFu
      class Request
        module Base
          def new_meth(url_params, query_params = {})
            curb = old_meth url_params, query_params
            curb.follow_location = true
            curb
          end
    
          alias :old_meth :build
          alias :build :new_meth
        end
      end
    end
    
    #this should follow the redirect because we instruct
    #Curb.follow_location = true
    print CurbFu.get('http:///').body
    

提交回复
热议问题