错误的状态行:"<!DOCTYPE HTML PUBLIC \" - // IETF // DTD HTML 2.0 // EN \">"

aca*_*cia 9 ruby xml ruby-on-rails

当我发出http请求时,我收到一个奇怪的错误.

请求代码是这样的;

purchase_xml = Transaction.yo_xml(api_username,api_password,@total, account, merchant_reference)
            uri = URI.parse(url)
            http = Net::HTTP.new(uri.host, uri.port)
            request = Net::HTTP::Post.new(uri.request_uri)
            request.body = purchase_xml
            response = http.request(request)
            result = Hash.from_xml(response.body)
Run Code Online (Sandbox Code Playgroud)

yo_xml看起来像这样;

def self.yo_xml(api_username, api_password,amount, account, transaction_id)
        xml = "<?xml version=1.0 encoding=UTF-8?><AutoCreate><Request><APIUsername>#{api_username}</APIUsername>
                <APIPassword>#{api_password}</APIPassword><Method>acdepositfunds</Method><Amount>#{amount}</Amount>
                <Account>#{account}</Account><Narrative>Purchase of SMS</Narrative><InternalReference>#{transaction_id}</InternalReference>
                <ExternalReference>#{transaction_id}</ExternalReference><ProviderReferenceText>Thank you for using Skyline SMS</ProviderReferenceText>
                </Request></AutoCreate>"
        return xml
    end
Run Code Online (Sandbox Code Playgroud)

我收到这个错误;

Net::HTTPBadResponse
wrong status line: "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">"
Run Code Online (Sandbox Code Playgroud)

提出这条线

response = http.request(request)
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏.

Gra*_*ett 16

在尝试通过https访问资源之前,我遇到了类似的错误.你没有提到,如果是这样的话,但如果是这样设置http.use_ssl = true的前post可能会解决它.