HttpError: InvalidUrl when attempting to send to cloudflare worker

Hi, I’m getting this HttpError: InvalidUrl error message when I’m attempting to send my discord webhook. This is what I get in the console:

However, I can curl the cloudflare endpoint with no issues and it sends the message:

I’m thinking it is something to do with Roblox’s way of formatting the request.

Here’s the script:

local HttpService = game:GetService("HttpService")

local webhookUrl = "<CLOUDFLARE_WORKER_URL>"

local discordWebhookUrl = "<WEBHOOK_URL>"

local function onPlayerJoin(player)
	local data = {
		author = player.Name,
		message = player.Name .. " has joined the game!",
		color = 0x00FF00
	}

	local body = {
		author = data.author,
		message = data.message,
		color = data.color
	}

	local jsonData = HttpService:JSONEncode(body)

	print("Sending JSON data: " .. jsonData)

	local encodedWebhookUrl = HttpService:UrlEncode(discordWebhookUrl)

	local requestUrl = webhookUrl .. "?webhookurl=" .. encodedWebhookUrl

	local response
	local success, err = pcall(function()
		response = HttpService:PostAsync(requestUrl, jsonData, Enum.HttpContentType.ApplicationJson)
	end)

	if success then
		print("Webhook sent successfully, response: " .. response)
	else
		print("Error sending webhook: " .. err)
	end
end

game.Players.PlayerAdded:Connect(onPlayerJoin)

Any help is welcome!

Try calling that url from outside Roblox and print the requestUrl variable in your Roblox code to see if it matches what you expect.