Created
October 24, 2016 02:36
-
-
Save gjyoung1974/d256278023f43569a8d4982f309eedec to your computer and use it in GitHub Desktop.
Call a SOAP API from Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//post to a SOAP API | |
var http = require('http'); | |
var s_Pan = '378282246310005'; //get the unprotected PAN from the form | |
var s_DPFormat = 'CC'; //get the data protection Format | |
var s_Identity = 'user@domain.com'; //get the data protection Format | |
var s_AuthInfo = 'p3ssw3rd'; //get the data protection Format | |
//Marshal up a ProtectFormattedData SOAP Mesage: | |
var soapRequest = | |
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:vib="http://voltage.com/vibesimple">' + "\n" + | |
' <soapenv:Header/>' + "\n" + | |
' <soapenv:Body>' + "\n" + | |
' <vib:ProtectFormattedData>' + "\n" + | |
' <dataIn>' + s_Pan + '</dataIn>' + "\n" + | |
' <format>' + s_DPFormat + '</format>' + "\n" + | |
' <identity>' + s_Identity + '</identity>' + "\n" + | |
' <tweak></tweak>' + "\n" + | |
' <authMethod>SharedSecret</authMethod>' + "\n" + | |
' <authInfo>' + s_AuthInfo + '</authInfo>' + "\n" + | |
' </vib:ProtectFormattedData>' + "\n" + | |
' </soapenv:Body>' + "\n" + | |
'</soapenv:Envelope>'; | |
var options = { | |
hostname: 'voltage-pp-0000.corp.acme.local', | |
port: 8181, | |
path: '/vibesimple/services/VibeSimpleSOAP', | |
method: 'POST', | |
headers: { | |
//'Content-Type': 'text/xml; charset=utf-8', is it this one or the follwing one? | |
'Content-Type': 'application/soap+xml; charset=utf-8', | |
'SOAPAction': 'http://voltage.com/vibesimple' | |
} | |
}; | |
var req = http.request(options, function (res) { | |
//TODO do something usefull with the response headers: | |
// console.log('headers:\n' + JSON.stringify(res.headers)); | |
res.setEncoding('utf8'); | |
res.on('data', function (chunk) { | |
console.log('body:\n' + chunk); | |
}); | |
}); | |
req.on('error', function (e) { | |
console.log('problem with request: ' + e.message); | |
}); | |
req.end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment