HTTP :: Message的未定义方法条

问题描述 投票:-1回答:1

我想用http客户端重写这段代码:

http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE

    request = Net::HTTP::Post.new(url)
    request.basic_auth(user, pass)
    request['content-type'] = 'application/xml'
    request['cache-control'] = 'no-cache'
    request.body = request_body

    response = http.request(request).body
    response = Response.new(response)
    check_for_approved_response(response)

进入这段代码:

request = HTTPClient.new()
request.set_auth(url, user, pass)

response = request.post(url, request_body)
response = Response.new(response)
check_for_approved_response(response)

但是当我运行代码时,我得到了这个结果:

undefined method `strip' for #<HTTP::Message:0x007fdbbf3cfdc8>
/Users/user/.rvm/gems/ruby-2.2.2/gems/nori-2.6.0/lib/nori.rb:43:in `parse'

在这一行:

Nori.new(parser: :nokogiri, advanced_typecasting: false, :convert_tags_to => lambda { |tag| tag.snakecase.to_sym }).parse(raw_response)

我试图要求:

require 'httpclient'
require 'active_support/all'
require 'active_support/core_ext'
require 'active_support/core_ext/object'

但我仍然得到这个错误。你知道我怎么解决这个问题吗?

ruby
1个回答
0
投票

看起来Nori期望字符串不是HTTP :: Message对象。你应该直接传递raw_response.body而不是raw_response对象吗?

Nori.new(parser: :nokogiri, advanced_typecasting: false, :convert_tags_to => lambda { |tag| tag.snakecase.to_sym }).parse(raw_response.body)
© www.soinside.com 2019 - 2024. All rights reserved.