Send an xml post request to an https site

I am trying to setup a new mobile payment solution and am having trouble
testing an xml post request that I need to make to the carrier’s site.
Here’s what I am using to test with right now. Keep in mind I’ve
changed the key to example for security reasons.

require ‘net/http’
require ‘uri’

uri = ‘https://pay01.zong.com/zongpay/actions/default?method=lookup

xml_req =<<EOF

examplekey
US


EOF

req = URI.escape(xml_req)

res = Net::HTTP.post_form(uri, req)

puts res.body

The site requires an xml request and everything listed in the xml_req is
what is required by the site.

The site URI is located in the uri and it is an https site.

Any help would be appreciated.

Alpha B. wrote in post #1004748:

The site requires an xml request

What type of request? POST? GET? Other?

Also,

Here is an example they use for PHP, in case you need one for reference:

Okay, I’ve been trying several things for quite a few hours and am
having no luck getting this to work. I could definitely use some help
here.

Here’s a gist of what I’m trying now:

Keep in mind that the customer key is blank here because I can’t give
that part out. Here is what the document says it requires for the site:

ZONG Docs

URI
https://pay01.zong.com/zongpay/actions/default?method=lookup

HTTP Method POST

Parameter is ‘request’
Value is an XML formatted request message

Format for the request message is below:

<?xml version="1.0" encoding="UTF-8"?><requestMobilePaymentProcessEntrypoints

xmlns=“http://pay01.zong.com/zongpay"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://pay01.zong.com/zongpay/zongpay.xsd”>
yourcustomerkey
US

And finally…

Here is what a sample response will look like:

zong.rb · GitHub (at the very bottom)

I’m not sure what I’m doing wrong here. Any ideas?

Alpha B. wrote in post #1004748:

I am trying to setup a new mobile payment solution and am having trouble
testing an xml post request that I need to make to the carrier’s site.
Here’s what I am using to test with right now. Keep in mind I’ve
changed the key to example for security reasons.

require ‘net/http’

Try require ‘net/https’, and look in the source code for examples of how
to use it, e.g.
/usr/lib/ruby/1.8/net/https.rb or wherever it is on your system

(If you are on an older version of Debian or Ubuntu which breaks ruby
into shrapnel, then this file is missing by default. You’ll need to
apt-get install another package, I think it’s libopenssl-ruby1.8 or
something like that)

HTH,

Brian.

The request has to be POST.

I already switched to net/https and posted the example in my previous
post. I’ll look through the code again, but I thought I was using it
correctly. I’m getting to the page and I’m not getting a forbidden but
its showing a not found.

I tested the lookup page using a manual page they gave me and I’m able
to get to it, just not with the implemented page. So, I’m doing
something wrong - I’m just not sure what.

All of the code I’m using is in my latest gist above or here. I even
supplied what I’m receiving in the gist.

Okay here’s a great example of the full URI string that works to achieve
the result I’m looking for:

https://pay01.zong.com/zongpay/actions/default?method=lookup&request=<?xml%20version="1.0"%20encoding="UTF-8"?> <requestMobilePaymentProcessEntrypoints%20xmlns="http://pay01.zong.com/zongpay"%20xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"%20xsi:schemaLocation="http://pay01.zong.com/zongpay/zongpay.xsd"> %20%20<customerKey>sometestkey</customerKey> %20%20<countryCode>US</countryCode> %20%20<items%20currency="USD"%20/> </requestMobilePaymentProcessEntrypoints>

If you click on this link, you’ll see the invalid customer key, which is
fine. If I place the customer key in the right spot and just paste the
URI in a browser, it works perfectly.

So, how can I translate this within the class I posted?

The breakdown is:

URI (https://pay01.zong.com/zongpay/actions/default?method=lookup)
Request is (&request=[escaped xml string])

Okay, to make it easier to read, I wrote a simple class including all of
the various pieces, including comments on what I tried, and the return
values.

I updated the latest gist here:

It should be easy to follow. I’m following all of the requirements:

The xml is a post request.
The request parameter is using escaped xml. I even tried not escaping
it.

I’ve noticed that when I printed out the path, their ?method=lookup is
not in the path. So, I tried altering my own path and you’ll see
approx. 6 or 7 different @data variables that I tested trying to mimic
the request. I believe I’ve covered every data scenario I could post.

I cleaned up the ssl bit and again, I have checked everything regarding
net/https, including the examples. Everything should be working, but
it’s not. If I’m missing something I don’t know what it is.

Any help would be appreciated. For anyone that does help, you can still
place “any” key in. If you reach the right page and receive the right
response, you should retrieve a forbidden response. I’m not getting my
true response or a forbidden response.

Thanks.

I figured it out myself.

All of my code was perfect except one piece:

#response = http.post(@uri.path, @data, @headers)
response = http.post(@uri.path, @data)

The @headers were causing the issue. Once I removed @headers everything
worked fine.

@elricstorm , did you include the headers in the data? Did it just not need headers?