Unallowed character in header

I’m trying to send data from my game’s datastores to a webserver that sends it to a channel, though when I do the following code

require(script.Parent.Components.SendResponse):Send("true", "This user is banned! Here is their ban information:\n\nModerator: " .. banData.moderator .. "\nReason: " .. banData.reason)

I get this error

I’m not sure how the quotation symbol is getting in the message string

This is an example of a ban request sent by the webserver

{"author":"zachariapopcorn#8105","usernameToBan":"ROBLOX","reason":"Another test 101","type":"Ban","channelID":"759959421085417533","authorID":"465362236693807115"}

This is the code that’s the SendResponse module

local module = {}

function module:Send(suc, message)
	game:GetService("HttpService"):RequestAsync({
		Url = _G.baseReplUrl .. _G.verifyRequestEndpoint,
		Method = "POST",
		Headers = {
			["Content-Type"] = "application/json",
			["success"] = suc,
			["message"] = message
		}
	})
end

return module

This isn’t a code problem, but a key problem, I’m not sure which keyboard you’re using, but it says it has a character that isn’t allowed, try to copy and paste his character ". Your keyboard could have a special " character.

Hi, I’m a little rusty on this, but maybe you could try “\r\n” instead of “\n” for new lines in your HTTP request. I believe the protocol to delimit new lines should be the sequence CR LF (i.e. \r\n) instead of just LF (i.e. \n).

This is as according to the RFC 2616.

1 Like

I have a standard US keyboard, so I don’t think that’s the problem

If I print the actually message, nothing seems wrong with it, though I’ll try with \r\n

Just tried with \r\n, still errors

require(script.Parent.Components.SendResponse):Send("true", "This user is banned! Here is their ban information:\r\n\r\nModerator: " .. banData.moderator .. "\r\nReason: " .. banData.reason)

Ah, apologies for the earlier response. So it seems that \r \n aka CR LF are not allowed in HTTP header field values. Might I suggest including the “message” and “success” fields in the body of the request instead of the header?

When I tried setting it in the body, it didn’t work

Edit: I might actually just hard code it into the system, though thanks for trying to help me

Sometimes throwing tostring() on things that are already strings seems to work. When you concat the string with the ban info, wrap the ban info in a tostring() like so:

local mod = require(script.Parent.Components.SendResponse)
mod:Send("true", "This user is banned! Here is their ban information:\n\nModerator: " .. tostring(banData.moderator) .. "\nReason: " .. tostring(banData.reason))

That seems a bit odd, though I’ll try it right now

Edit: Nope, doesn’t work, I’m just going to hard code it cause I want to move progress on this

You’ve probably moved on from this, but what was the error when you tried to put it in the body? Was it the same as before?

1 Like

It wasn’t attaching to the body

When you say “wasn’t attaching to the body” do you mean that an exception was thrown (eg. A string was expected. [Meaning that you may have forgotten to encode it with :JSONEncode]) or the data was somehow not received on the web server?

1 Like

Data wasn’t received on webserver