在经典ASP中使用Microsoft.XMLHTTP将JSON结果发布为空白内容

时间:2019-06-28 15:38:48

标签: vbscript asp-classic

这让我感到困惑了一段时间。 我正在尝试将JSON内容发布到Webhook,但需要使用Classic ASP。 我可以使用jquery来做到这一点,但需要在服务器端。 我也尝试过使用JScript导致相同的问题。还尝试了单独的服务器

该脚本从根本上起作用,如果我将Content-Type设置为application/x-www-form-urlencoded,发布的内容就可以正常使用,但是一旦我更改为application/json,该内容就会消失(请求使它消失了)虽然我可以检查另一端的标题)

strEnvelope = "{""content"":""Serverside Test Post"",""embeds"": [{""description"":""Now to grab and extract content""}]}"
data = "content="&Server.URLEncode(strEnvelope)

dim xmlhttp 
set xmlhttp = server.Createobject("Microsoft.XMLHTTP")
xmlhttp.Open "POST","https://discordapp.com/api/webhooks/000000000000/key",false
'xmlhttp.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.setRequestHeader "Content-Type", "application/json"
xmlhttp.send(data)
Response.Write xmlhttp.ResponseText
Set xmlhttp = nothing

任何人都非常感激,这很奇怪,因为我所做的只是更改Content-Type标头

1 个答案:

答案 0 :(得分:2)

老实说,我不知道为什么,但是它开始起作用了。

最初,我尝试通过stringify函数(如果要搜索google,由Fabio Zendhi Nagao编写的JSON Parser)创建json字符串,并注意到它可以正常工作。

但是后来我注意到其他一些较早的测试也在起作用。

目前,我将其归结为:

xmlhttp.setRequestHeader "Accept","application/json"

但是,这是在较早的测试中失败的-它正在运行,所以我没有抱怨:-)