-
-
Save circa10a/f6f7c9d8d5e4118e6cf2202262b2fddf to your computer and use it in GitHub Desktop.
const soapRequest = require('easy-soap-request'); | |
const fs = require('fs'); | |
// example data | |
const url = 'https://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php'; | |
const sampleHeaders = { | |
'user-agent': 'sampleTest', | |
'Content-Type': 'text/xml;charset=UTF-8', | |
'soapAction': 'https://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl#LatLonListZipCode', | |
}; | |
const xml = fs.readFileSync('test/zipCodeEnvelope.xml', 'utf-8'); | |
// usage of module | |
(async () => { | |
const { response } = await soapRequest({ url: url, headers: sampleHeaders, xml: xml, timeout: 1000 }); // Optional timeout parameter(milliseconds) | |
const { headers, body, statusCode } = response; | |
console.log(headers); | |
console.log(body); | |
console.log(statusCode); | |
})(); |
How to handle the security here?
I'm getting a http 405 method not allowed - any idea?
@salokod maybe the server you are hitting doesn't allow POST requests? Perhaps PUTS?
allow: 'GET,OPTIONS',
'content-type': 'application/json',
'content-length': '52'
},
is part of the response, does that mean I have to use a GET command? Can I do so with this easy-soap-request?
@salokod yes, you can pass the method
option like so as of version 4.1.3
await soapRequest({ method: 'GET', url, headers, data: <some json or xml> });
I keep getting the WSDL definition back:
<soap:binding style='document' transport='http://schemas.xmlsoap.org/soap/http'></soap:binding>
<soap:operation soapAction='https://my-server.com:8482/ws/GetJob'></soap:operation>
<soap:body use='literal'></soap:body>
<soap:body use='literal'></soap:body>
<soap:address location='https://my-server.com:8482/ws/GetJob'></soap:address>
text/xml, text/html, image/gif, image/jpeg, *; q=.2, /; q=.2
Any idea what I could be doing wrong? It's driving me nuts. I got the SOAP envelope from SOAP UI - here is the example:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://www.northgate-is.com/proiv/webservices/types">
soapenv:Header/
soapenv:Body
typ:GetJob
<Authorization_ID>AUTHID</Authorization_ID>
</typ:GetJob>
</soapenv:Body>
</soapenv:Envelope>
That's what I would expect from a GET request. You need to hit the /GetJob
endpoint I suspect. But I know nothing of this API. You would need to consult the maintainer or check for API consumption documentation
@talesmgodois I've had success with xml2js