我基本上是经典ASP和VBScript的菜鸟,所以我想得到一些帮助来实现我在这里的目标。我已经构建了一个JSON字符串,我需要使用VBScript将其发送到RESTful Web服务。我该怎么做?
我有一些代码,但我认为它不起作用:
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
答案 0 :(得分:3)
您不需要将JSON转换为XML(因为它是JSON而不是XML和所有):
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