HTTP.post_form in Ruby with custom headers

前端 未结 4 983
刺人心
刺人心 2021-01-14 20:07

Im trying to use Nets/HTTP to use POST and put in a custom user agent. I\'ve typically used open-uri but it cant do POST can it?

4条回答
  •  我在风中等你
    2021-01-14 20:36

    You can try this, for example:

    http = Net::HTTP.new('domain.com', 80)
    path = '/url'
    
    data = 'form=data&more=values'
    headers = {
      'Cookie' => cookie,
      'Content-Type' => 'application/x-www-form-urlencoded'
    }
    
    resp, data = http.post(path, data, headers)
    

提交回复
热议问题