开发者

Net::HTTP POST with XML Payload and some URL Parameters

开发者 https://www.devze.com 2023-01-13 23:36 出处:网络
Just a quick question, when I do request = Net::HTTP::Post.new(path) Can I do path = \'/api/v1/baskets?apiKey=\' + api_key + \'&sig=\' + sig + \'&time=\' + time

Just a quick question,

when I do

request = Net::HTTP::Post.new(path)

Can I do

path = '/api/v1/baskets?apiKey=' + api_key + '&sig=' + sig + '&time=' + time

Where api_key sig开发者_如何学JAVA and time are some string

or do I need to do

path = '/api/v1/baskets'
request.set_form_data({'apiKey' => api_key, 'sig' => sig, 'time' => time})

is there any difference or are they pretty much the same?


They are pretty much the same, set_form_data does a urlencode.

Here is what it does in set_form_data link

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

When in doubt always refer ruby-doc.org.

0

精彩评论

暂无评论...
验证码 换一张
取 消