Go Premium for a chance to win a PS4. Enter to Win


How to send an HTTPS POST to an external URL and receive response using Classic ASP

Posted on 2014-04-23
Medium Priority
Last Modified: 2014-05-07
Many years ago, I needed a way to send POST requests via HTTPS in order to interact with APIs such as Authorize.Net and UPS Online Tools, among others, from my Classic ASP pages.

I found a Windows server component (DLL) called KHTTP that would send out the requests and put the results into an ASP variable. It worked with HTTP and HTTPS, as well as regular POST and XML data, could pull in the content from any external URL (even if not POSTing data), and I have used it with a variety of APIs (and for other purposes) over the years. The component seems to be out-of-date at this point, although I still use it for many websites since it works well at what it does:


However, at the moment, I am trying to do HTTPS POST requests to one of the PayPal APIs. KHTTP does not seem to be working, because (I am told by PayPal tech support) it is likely the component is making my data urlencoded.

I'm a little confused by that, because I have used it successfully with many other APIs… notable ones too, such as the aforementioned Authorize.Net and UPS Online Tools. I don't know why their requirements for a POST request would be different from PayPal's.

I even setup my own listener, received my own POST, and the data seems to come through fine.

I don't fully understand the urlencoded issue, I thought that is something related to GET requests, not POST.

Using KHTTP, I don't have any option to send the data any other way. I simply assign a bunch of name/value pairs, I have the option to POST or GET, then put in the https URL, and the component does the rest, putting the response into a variable.

So if PayPal tech support is right, then a different component/utility function would be the next thing to try.

So, I need an alternative to KHTTP that will interface correctly with PayPal's API. Does this need to be a DLL that I install on the server? Or is there some other way to do this? It has been a long while since I have researched this kind of thing. All I really need to do is:

1. Assign name/value pairs.
2. POST to PayPal's API.
3. Receive the response back.

Would really appreciate any advice.
Thank you!
Question by:bbdesign
  • 6
  • 5
  • 3
LVL 54

Accepted Solution

Scott Fell,  EE MVE earned 2000 total points
ID: 40018697
Below is a function I have for something similar.

The top portion creates the xml soap to be posted.  If you were to response.write the strRequest, you would get the xml.  

Where you see, Dim objXMLHTTP is the start of sending the post to the url

strResult is where the results (xml) is held and below that you can see how I am parsing the xml.

function searchTransactions(SalesOrderID)

strRequest =""
strRequest =strRequest&"<?xml version=""1.0"" encoding=""UTF-8""?>"
strRequest =strRequest&"<SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" "
strRequest =strRequest&"xmlns:ns1=""urn:usaepay"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" "
strRequest =strRequest&"xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" "
strRequest =strRequest&"xmlns:SOAP-ENC=""http://schemas.xmlsoap.org/soap/encoding/"" "
strRequest =strRequest&"SOAP-ENV:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"">"
strRequest =strRequest&"<SOAP-ENV:Body>"

strRequest =strRequest&"<ns1:searchTransactions> "

strRequest =strRequest&"<Token xsi:type=""ns1:ueSecurityToken"">"
strRequest =strRequest&"<ClientIP xsi:type=""xsd:string"">"& clientip &"</ClientIP>"
strRequest =strRequest&"<PinHash xsi:type=""ns1:ueHash"">"
strRequest =strRequest&"<HashValue xsi:type=""xsd:string"">"& hash &"</HashValue>"
strRequest =strRequest&"<Seed xsi:type=""xsd:string"">"& seed &"</Seed>"
strRequest =strRequest&"<Type xsi:type=""xsd:string"">"& hashtype &"</Type>"
strRequest =strRequest&"</PinHash>"
strRequest =strRequest&"<SourceKey xsi:type=""xsd:string"">"& sourcekey &"</SourceKey>"
strRequest =strRequest&"</Token>"

strRequest =strRequest&"<Search SOAP-ENC:arrayType=""ns1:SearchParam[1]"" xsi:type=""ns1:SearchParamArray""> "
strRequest =strRequest&"<item xsi:type=""ns1:SearchParam""> "
strRequest =strRequest&"<Field xsi:type=""xsd:string"">Invoice</Field> "
strRequest =strRequest&"<Type xsi:type=""xsd:string"">eq</Type> "
strRequest =strRequest&"<Value xsi:type=""xsd:string"">"&SalesOrderID&"</Value> "
strRequest =strRequest&"</item> "
strRequest =strRequest&"</Search> "
strRequest =strRequest&"<MatchAll xsi:type=""xsd:boolean"">true</MatchAll> "
strRequest =strRequest&"<Start xsi:type=""xsd:integer"">0</Start> "
strRequest =strRequest&"<Limit xsi:type=""xsd:integer"">10</Limit>" 
strRequest =strRequest&"<Sort xsi:type=""xsd:string"">created</Sort> "

strRequest =strRequest&"</ns1:searchTransactions> "

strRequest =strRequest&"</SOAP-ENV:Body> "
strRequest =strRequest&"</SOAP-ENV:Envelope>"

set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")

strURL = PostToUrl
objXMLHTTP.setTimeouts 10000, 60000 , 60000, 360000 
   objXMLHTTP.open "POST", "" & strURL & "" , False
   objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
   objXMLHTTP.setRequestHeader "Content-Length", Len(strRequest)

   strResult = objXMLHTTP.responseText

dim getCustPayMethText

    Set objReturn = CreateObject("MSXML2.DOMDocument.3.0")
    objReturn.loadXML objXMLHTTP.responseText

' ********** READ XML OUTPUT *********'

if not objReturn.getElementsByTagName("TransactionsMatched").Item(0) is Nothing  then
	TransactionsMatched=			objReturn.getElementsByTagName("TransactionsMatched").Item(0).text
end if
if cdbl(TransactionsMatched)>0 then
for x = 0 to cint(TransactionsMatched)-1

if not objReturn.getElementsByTagName("RefNum").Item(x) is Nothing  then
	RefNum=			objReturn.getElementsByTagName("RefNum").Item(x).text
end if

if not objReturn.getElementsByTagName("Result").Item(x) is Nothing  then
	Result=			objReturn.getElementsByTagName("Result").Item(x).text
end if

if not objReturn.getElementsByTagName("ResultCode").Item(x) is Nothing  then
	ResultCode=			objReturn.getElementsByTagName("ResultCode").Item(x).text
end if

if not objReturn.getElementsByTagName("CardNumber").Item(x) is Nothing  then
	CardNumber=			objReturn.getElementsByTagName("CardNumber").Item(x).text
end if

if not objReturn.getElementsByTagName("TransactionType").Item(x) is Nothing  then
	TransactionType=			objReturn.getElementsByTagName("TransactionType").Item(x).text
end if

if ResultCode = "A" then
	searchTransactions="Not Approved"
end if

end Function

Open in new window

LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 40018715
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 40018724
Looking at paypal you can see their soap header https://developer.paypal.com/docs/classic/api/PayPalSOAPAPIArchitecture/

<RequesterCredentials xmlns="urn:ebay:api:PayPalAPI" xsi:type="ebl:CustomSecurityHeaderType">
<Credentials xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="ebl:UserIdPasswordType">

Open in new window

Where you see items like
that could be

' or


Open in new window

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Author Comment

ID: 40018759
You appear to be using XML in all of these cases. Isn't that different than regular POST "name value pairs"? In fact, the DLL I was using (KHTTP) had a switch that I had to use, to tell it I was posting XML data rather than "regular" data (which I assume is the same as what an HTML form would send, as opposed to XML)?

I'm not sure how to format non-XML data, if that is in fact what PayPal wants. That other answer you pasted above looks kind of promising too, so I will check that out.

Or maybe I am overcomplicating this, and its basically the same thing?

LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 40018806
The api from paypal I  looked up requires SOAP.  

For a direct post  http://support.microsoft.com/kb/290591
	DataToSend = "id=1"
	dim xmlhttp 
	set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
	xmlhttp.Open "POST","http://somesite.com/Receiver.asp",false
	xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
	xmlhttp.send DataToSend
	Response.ContentType = "text/xml"
	Response.Write xmlhttp.responsexml.xml
        Set xmlhttp = nothing

Open in new window

LVL 84

Expert Comment

by:Dave Baldwin
ID: 40018868
That's an interesting comment from the Paypal tech.  I'm using the Express Checkout API and everything that is posted is (and must be) urlencoded.  That is standard practice throughout the web.  Some simple values without any punctuation or special characters can be sent without urlencoding but everything else needs it.  I'm sure that if you looked at the data that Scott's code is sending you would see that it is definitely urlencoded.
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40018879
Your link for KHTTP is no longer valid, it redirects to some other web site.
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 40018889
ChillKat has this but you don't need it.  http://www.chilkatsoft.com/HttpActiveX.asp
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40018896
But I can't check KHTTP for this question if I can't download it.

Author Comment

ID: 40019065
I am using this for Payflow Gateway. Does that tell you anything, regarding SOAP and so forth?
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 40019092
Since the question here was about how to do an httppost, I think we have shown that. To prevent this question from getting off tangent, see if what we have shown makes sense.

As for integrating with paypal, I would suggest reading up and giving it a try.  We will need more details on your next question such as which exact api are you using, what code have you tried, what error are you getting.

There is payflow link https://www.paypal.com/webapps/mpp/referral/paypal-payflow-link and payflow pro https://www.paypal.com/webapps/mpp/referral/paypal-payflow-pro which is going to be more like what you used on authorize.net.  

Paypal pro has developer info https://developer.paypal.com/docs/classic/products/payflow-pro/  and you will see a list of pdf's.  One shows you can use either xml or name value pairs https://www.paypalobjects.com/webstatic/en_US/developer/docs/pdf/pp_payflowpro_guide.pdf   
=John&LASTNAME=Jones&STREET=123 Main St.&CITY=San 

Open in new window

Using this example http:#a40018806 you might be able to add that information in the "datatosend" variable.

Author Comment

ID: 40019678
Thank you so much, I will be checking into all of this later today.

Author Comment

ID: 40044667
In order to verify that I am sending the data correctly, I am trying to setup a listener to bounce back what it is receiving. Before I started messing around with XML, I was using regular FORM-style post data, and I wrote this simple ASP script:

for each item in request.form
            response.write(item & "=" & request.form(item) & chr(13) & chr(10))

How can I do something similar for my XML data so I can know for sure what I am sending?

Author Comment

ID: 40048070
Sorry for the long delay, I was able to get this to work using the sample code provided above. Thank you!

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question