0

使用 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
4

1 回答 1

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
于 2013-07-01T18:11:46.293 回答