From: Klesh Date: 2008-10-16T13:14:41+09:00 Subject: [ruby-core:19348] Net::HTTP form_data Array support ------=_Part_107725_29367774.1224130501447 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, When using some http request posting function like post_form, the params can only support simple Hash type, an Array cannot be converted to form_data correctly so I make some changings in net/http stdlib: line 1435 from def set_form_data(params, sep = '&') self.body = params.map {|k,v| "#{urlencode(k.to_s)}=#{urlencode(v.to_s)}" }.join(sep) self.content_type = 'application/x-www-form-urlencoded' end to # supports { 'name' => ['hello', 'world'] to name=hello&name=world def set_form_data(params, sep = '&') self.body = params.map {|k,v| if v.instance_of?(Array) v.map {|e| "#{urlencode(k.to_s)}=#{urlencode(e.to_s)}"}.join(sep) else "#{urlencode(k.to_s)}=#{urlencode(v.to_s)}" end }.join(sep) self.content_type = 'application/x-www-form-urlencoded' end Best Regards Klesh Wong ------=_Part_107725_29367774.1224130501447 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
Hi,

  When using some http request posting function like post_form, the params can only support simple Hash type, an Array cannot be converted to form_data correctly


so I make some changings in net/http stdlib:

   line 1435

   from
    def set_form_data(params, sep = '&')
      self.body = params.map {|k,v| "#{urlencode(k.to_s)}=#{urlencode(v.to_s)}" }.join(sep)
      self.content_type = 'application/x-www-form-urlencoded'
    end
   to
    # supports { 'name' => ['hello', 'world']   to  name=hello&name=world
    def set_form_data(params, sep = '&')

      self.body = params.map {|k,v|
        if v.instance_of?(Array)
          v.map {|e| "#{urlencode(k.to_s)}=#{urlencode(e.to_s)}"}.join(sep)
        else
          "#{urlencode(k.to_s)}=#{urlencode(v.to_s)}"
        end
      }.join(sep)
      self.content_type = 'application/x-www-form-urlencoded'
    end

  Best Regards


Klesh Wong

------=_Part_107725_29367774.1224130501447--