1

This has been baffling me for a while. I'm trying to post JSON content to a webhook but need to use Classic ASP. I can do it using jquery but needs to be serverside. I've also tried using JScript which results in the same issue. Also tried a separate server

The script fundamentally works, If I set the Content-Type to application/x-www-form-urlencoded the posted content comes through fine, but as soon as I change to application/json the content disappears (the request makes it though as I can inspect the headers at the other end)

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

Any thoughts much appreciated, it's weird as all I'm doing is changing the Content-Type header

JustinReid
  • 192
  • 10
  • You could use [this answer](https://stackoverflow.com/a/15818268/1682881) to access the posted json. – Flakes Jun 30 '19 at 16:08
  • Thanks for the response @SearchAndResQ, that seems to be about reading the response, my problem was it wasn't posting anything at all. However, it seems to be working now (my update is below) – JustinReid Jul 01 '19 at 12:16

1 Answers1

2

I honestly don't know why, but it's started working.

Initially, I tried creating the json string via stringify function (JSON Parser written by Fabio Zendhi Nagao if you want to google) and noticed it working.

But then I noticed some other earlier tests working.

At the moment I'm putting it down to to the inclusion of:

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

However, this was in earlier tests which failed - It's now working so I ain't complaining :-)

JustinReid
  • 192
  • 10