wrong status line: "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">"

19,688

Solution 1

I have gotten an error similar to this before trying to access a resource over https. You didn't mention if that was the case, but if so setting http.use_ssl = true before the post might fix it.

Solution 2

This is how i got it to work

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
            http.use_ssl = true
            http.verify_mode = OpenSSL::SSL::VERIFY_NONE
            response = http.request(request)
            result = Hash.from_xml(response.body)
Share:
19,688
acacia
Author by

acacia

Updated on July 23, 2022

Comments

  • acacia
    acacia almost 2 years

    I am getting a weird error when i make http request.

    The request code is like this;

    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)
    

    Where the yo_xml looks like this;

    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
    

    I am getting this error;

    Net::HTTPBadResponse
    wrong status line: "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">"
    

    raised o this line

    response = http.request(request)
    

    Any help is appreciated.