Send a JSON string to a RESTful WS from Classic ASP

匿名 (未验证) 提交于 2019-12-03 09:14:57

问题:

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 

回答1:

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 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!