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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With