Skip to content

Instantly share code, notes, and snippets.

@marshluca
Last active October 15, 2015 01:56
Show Gist options
  • Save marshluca/9dc4c02ff839ebd19b1c to your computer and use it in GitHub Desktop.
Save marshluca/9dc4c02ff839ebd19b1c to your computer and use it in GitHub Desktop.
require 'net/http'
# Create the SOAP Envelope
data = <<-EOF
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetInvoiceNumber xmlns="testinvoice.PayNow.com.tw">
<mem_cid>70828783</mem_cid>
<Year>2015</Year>
<period>4</period>
</GetInvoiceNumber>
</soap:Body>
</soap:Envelope>
EOF
# Post the request
http = Net::HTTP.new('testinvoice.PayNow.com.tw', 80)
http.use_ssl = false
path = '/GetInvoiceNumber'
headers = {
'Referer' => 'https://www.maicoin.com',
'Content-Type' => 'text/xml',
'Host' => 'testinvoice.PayNow.com.tw'
}
resp, data = http.post(path, data, headers)
# Output the results
puts 'Code = ' + resp.code
puts 'Message = ' + resp.message
resp.each { |key, val| puts key + ' = ' + val }
puts data.inspect
# Output:
# Code = 404
# Message = Not Found
# content-type = text/html
# server = Microsoft-IIS/7.5
# x-powered-by = ASP.NET
# date = Thu, 15 Oct 2015 01:49:59 GMT
# connection = close
# content-length = 1161
# nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment