HTTP request body is nil?

Hi!

I’m trying to make a script that does the following:

  • A user inputs a ‘password’ in a textbox.
  • Once enter is pressed, RemoteEvent fires to save the input.
  • A serverscript executes a HTTP request to a site which encrypts the input from the textbox to base64.
  • The serverscript takes the body of the response (base64) for an authentication header.

I currently have the following LocalScript:

local HTTPService = game:GetService("HttpService")

script.Parent.FocusLost:Connect(function(enterPressed, inputThatCausedFocusLost)
	if enterPressed then
		local input = script.Parent.Text
		wait()
		game.ReplicatedStorage.AuthEvent:FireServer(input)
	end
end)

It waits for the user to press enter and fires a RemoteEvent to save the input.

I have the following Server script:

local HTTPService = game:GetService("HttpService")

game:GetService("ReplicatedStorage"):WaitForChild("AuthEvent").OnServerEvent:Connect(function(plr, input)
	print("INPUT: " .. tostring(input) )

	local yees = HTTPService:RequestAsync({
		Url = "REDACTED URL",
		Method = "POST",
		Headers = {
			["Content-Type"] = "application/x-www-form-urlencoded"
		},
		Body = tostring(input) --the input from gui
	})

	print("-")
	for _, v in pairs(yees) do
		if typeof(v) ~= "table" then
			print("  " .. tostring(v))
		else
			for _, v in pairs(v) do
				if typeof(v) ~= "table" then
					print("         " .. tostring(v))
				end
			end
		end
	end
	print("-")

	if yees.Body == "" then
		print("BODY is nil.. how did this happen?")
	else
		print("BODY: " .. yees.Body) --debug
	end

	local encryptedSelfScpf = HTTPService:RequestAsync({
		Url = "REDACTED URL",
		Method = "GET",
		Headers = {
			["Content-Type"] = "application/json",
			["Authorization"] = "Basic "..yees.Body
		},
	})
		
	print("OUTPUT: " .. encryptedSelfScpf.Body)

end)

No matter the input, yees.Body is always nil, which results in an ‘Unauthorized Access’ response. I’ve tried some things, but to no avail. Any help is appreciated. If this is impossible, is there any alternative way? Thanks in advance.

Try Insert print("Status code:", response.StatusCode, response.StatusMessage) after local yees = HTTPService:RequestAsync

Unfortunately that didn’t fix anything, thanks though.

Managed to fix it myself, it was a rather simple error.

Included:

Body = "text="..tostring(input)