This question already has an answer here:
- Simplest SOAP example 11 answers
I have this soap call as shown below-
POST /axis/services/G2A_PhoneMode HTTP/1.1 Content-Length: 609 User-Agent: Crosscheck Networks SOAPSonar Content-Type: text/xml; charset=utf-8 SOAPAction: "" <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns0="G2A_Sessions"> <soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <tns0:logon> <loginId xsi:type="xsd:string">user@company.com</loginId> <password xsi:type="xsd:string">somePassword</password> <version xsi:type="xsd:long">1</version> </tns0:logon> </soap:Body> </soap:Envelope>
What will the equivalent soap post call for the above code in javascript. I've to call it from javascript code.
I'm new to this, and what I've tried is,
<html> <head> <title> Soap Api Test </title> </head> <body> <div id="result"> </div> <script> function logOnAgent(){ var xmlhttp = new XMLHttpRequest(); xmlhttp.open('POST', 'https://axis/services/G2A_PhoneMode/', true); var str = '<?xml version="1.0" encoding="utf-8"?>' + '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns0="G2A_Sessions">' + '<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">' + '<tns0:logon>' + '<loginId xsi:type="xsd:string">user@company.com</loginId>' + '<password xsi:type="xsd:string">somePassword</password>' + '<version xsi:type="xsd:long">1</version>' + '</tns0:logon>' + '</soap:Body>' + '</soap:Envelope>'; xmlhttp.setRequestHeader("Content-Length","609"); xmlhttp.setRequestHeader("User-Agent","Crosscheck Networks SOAPSonar"); xmlhttp.setRequestHeader("Content-Type","text/xml"); xmlhttp.setRequestHeader("Content-Type","text/xml"); xmlhttp.send(str); var msg = xmlhttp.responseText; document.getElementById("result").innerHTML = msg; } logOnAgent(); </script> </body> </html>
I don't know where I'm going wrong. Thank you in advance .........
No comments:
Post a Comment