Posting Message to a Discord Server

Hi All,

I am on Windows 11, Xojo 2024.1
I am trying to send a message to a Discord server from a Desktop Application.
This link explains how to do that.

This is, I believe the most important bit of code in that example:

    function sendMessage() {
      const request = new XMLHttpRequest();
      request.open("POST", "https://discordapp.com/api/webhooks/************");

      request.setRequestHeader('Content-type', 'application/json');

      const params = {
        username: "My Webhook Name",
        avatar_url: "",
        content: "The message to send"
      }

      request.send(JSON.stringify(params));
    }

This is my code so far:

Var discordPost As New URLConnection
Var json As New JSONItem
Var sMsg As String

json.Value("username") = "AppPost"
json.Value("avatar_url") = ""
json.Value("content") = "This is a sample message from Xojo"

sMsg = json.ToString

discordPost.RequestHeader("Content-type") = "application/json"

discordPost.Send("OPEN", "https://discord.com/api/webhooks/*************")
discordPost.Send("POST", sMsg)
discordPost.Disconnect()

I know that the line discordPost.Send("POST", sMsg) is wrong, but I am unsure how to send the message after I have established the connection.

Any idea what that line should be?
Also I feel like I should be checking to make sure the connection is made. I assume a Try/Catch should be used here, but I don’t know what error type to be checking for.

Note: The series of asterisks is where, basically, an authentication token or API key goes, hence my masking it.

Thanks.

Nevermind. The URLConnection Post example works. I will use that for now.
Sorry for the noise.