I'm attempting to get a SOAP response from a web service without using any libraries in Node, but I'm getting nowhere with the code I have. The WSDL for the service can be found here. I've tested the request in SoapUI, and with curl in a batch file. The JavaScript:
const http = require('http')
const fs = require('fs')
const xml = fs.readFileSync('latlonzipcode.xml','utf-8')
const options = {
hostname : 'graphical.weather.gov',
path : '/xml/SOAP_server/ndfdXMLserver.php',
method : 'POST',
headers : {
'Content-Type' : 'text/xml;charset=utf-8',
'soapAction' : 'https://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl#LatLonListZipCode'
}
}
var obj = http.request(options,(resp)=>{
let data = ''
console.log(resp.statusCode)
console.log(resp.headers)
resp.on('data',(chunk)=>{
data += chunk
})
resp.on('end',()=>{
console.log(data)
})
}).on('error',(err)=>{
console.log("Error: " + err.message)
})
obj.write(xml)
obj.end()
The SOAP envelope/XML file:
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ndf="https://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl">
<soapenv:Header/>
<soapenv:Body>
<ndf:LatLonListZipCode soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<zipCodeList xsi:type="xsd:string">90210</zipCodeList>
</ndf:LatLonListZipCode>
</soapenv:Body>
</soapenv:Envelope>
and the .bat file - for testing:
:: curl options: -H is for Header --data allows file parameters
curl -H "soapAction: \"https://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl#LatLonListCityNames\"" -H "Content-Type: text/xml;charset=UTF-8" --data @latlonzipcode.xml https://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php > response.xml
The response I receive from the service:
403
{ server: 'AkamaiGHost',
'mime-version': '1.0',
'content-type': 'text/html',
'content-length': '320',
expires: 'Wed, 18 Jul 2018 14:18:05 GMT',
date: 'Wed, 18 Jul 2018 14:18:05 GMT',
connection: 'close' }
<HTML><HEAD>
<TITLE>Access Denied</TITLE>
</HEAD><BODY>
<H1>Access Denied</H1>
You don't have permission to access "http://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php" on this server.<P>
Reference #18.7fd23017.1531923485.f45e7526
</BODY>
</HTML>
The batch file works perfectly. Any help would be great. Thanks.
UPDATE
After Googling around I found this. So I added the header User-Agent : headerTest
to my options... And finally got a response, unfortunately it was
the WSDL.