Reputation: 1271
I am basically a noob in classic ASP and VBScript, so I would like to get some help to achieve the goal I have here. I've built a JSON string and I need to send it to a RESTful web service using VBScript. How do I do that?
I have some code, but I don't think it works:
strJSONToSend = JSONstr 'this is where I use my built JSON string
webserviceurl = "url here"
Set objRequest = Server.createobject("MSXML2.XMLHTTP.3.0")
objRequest.open "POST", webserviceurl, False
objRequest.setRequestHeader "Content-Type", "application/json; charset=UTF-8"
objRequest.setRequestHeader "CharSet", "utf-8"
objRequest.setRequestHeader "SOAPAction", webserviceurl
Set objJSONDoc = Server.createobject("MSXML2.DOMDocument.3.0")
objJSONDoc.loadXml strJSONToSend
objRequest.send objJSONDoc
set objJSONDoc = nothing
set objResult = nothing
Upvotes: 1
Views: 10410
Reputation: 3111
You don't need to convert the JSON to XML (since it's JSON and not XML and all):
strJSONToSend = JSONstr 'this is where I use my built JSON string
webserviceurl = "url here"
Set objRequest = Server.createobject("MSXML2.XMLHTTP.3.0")
objRequest.open "POST", webserviceurl, False
objRequest.setRequestHeader "Content-Type", "application/json; charset=UTF-8"
objRequest.setRequestHeader "CharSet", "utf-8"
objRequest.setRequestHeader "SOAPAction", webserviceurl
objRequest.send strJSONToSend
set objJSONDoc = nothing
set objResult = nothing
Upvotes: 3