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

2
  • You could use this answer to access the posted json. Commented Jun 30, 2019 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) Commented Jul 1, 2019 at 12:16

1 Answer 1

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 :-)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.