使用Ruby语言触发'GET'请求后,我无法得到xml响应。我的当前代码如下:
require 'net/https'
require 'uri'
require 'base64'
base_url = '<URL>'
app_guid = '<App GUID Value>'
format = "xml"
# Example using bug.fetch
params = {
"appGUID" => app_guid,
"format" => format,
"method" => "bug.fetch",
"bugId" => "1234567"
}
puts "XML Response"
res = Net::HTTP.post_form(URI.parse(base_url), params)
puts res.body
答案 0 :(得分:1)
正如Frederick所说,您的代码正在发出POST
请求。如果您想使用GET
执行:
uri = URI.parse(base_url)
uri.query = URI.encode_www_form(params)
res = Net::HTTP.get_response(uri)
如果您仍然遇到错误,您可能希望使用以下替代语法:
uri = URI.parse(base_url)
uri.query = URI.encode_www_form(params)
conn = Net::HTTP.new(uri.host, uri.port)
conn.use_ssl = true
res = conn.get uri.request_uri