1

我基本上是经典 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
4

1 回答 1

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
于 2012-04-16T20:46:09.300 回答