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

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!
Brad BansnerWeb DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
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="""" "
strRequest =strRequest&"xmlns:ns1=""urn:usaepay"" xmlns:xsd="""" "
strRequest =strRequest&"xmlns:xsi="""" "
strRequest =strRequest&"xmlns:SOAP-ENC="""" "
strRequest =strRequest&"SOAP-ENV:encodingStyle="""">"
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 "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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Looking at paypal you can see their soap header

<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

Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Brad BansnerWeb DeveloperAuthor Commented:
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?

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
The api from paypal I  looked up requires SOAP.  

For a direct post
	DataToSend = "id=1"
	dim xmlhttp 
	set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
	xmlhttp.Open "POST","",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

Dave BaldwinFixer of ProblemsCommented:
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.
Dave BaldwinFixer of ProblemsCommented:
Your link for KHTTP is no longer valid, it redirects to some other web site.
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
ChillKat has this but you don't need it.
Dave BaldwinFixer of ProblemsCommented:
But I can't check KHTTP for this question if I can't download it.
Brad BansnerWeb DeveloperAuthor Commented:
I am using this for Payflow Gateway. Does that tell you anything, regarding SOAP and so forth?
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
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 and payflow pro which is going to be more like what you used on  

Paypal pro has developer info  and you will see a list of pdf's.  One shows you can use either xml or name value pairs   
=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.
Brad BansnerWeb DeveloperAuthor Commented:
Thank you so much, I will be checking into all of this later today.
Brad BansnerWeb DeveloperAuthor Commented:
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?
Brad BansnerWeb DeveloperAuthor Commented:
Sorry for the long delay, I was able to get this to work using the sample code provided above. Thank you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.