1

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
user692942
  • 16,398
  • 7
  • 76
  • 175
Victor
  • 1,251
  • 6
  • 21
  • 43
  • 1
    What does not work exactly? The code seems fine-ish. No need to convert the JSON to XML though, like Nathan points out. – Guido Gautier Apr 17 '12 at 08:59
  • 1
    BTW, use `MSXML2.ServerXMLHTTP.3.0`. XMLHTTP should not be used in server-side code. Also are you sure you need to create that "CharSet" header, ordinarily the "Content-Type" specifies the charset of the entity body and you are already doing that. – AnthonyWJones Apr 17 '12 at 13:10

1 Answers1

3

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
user692942
  • 16,398
  • 7
  • 76
  • 175
Nathan Rice
  • 3,091
  • 1
  • 20
  • 30