Why can't we use "Content-Length" as HTTP PUT and POST header?

I want to send a HTTP PUT request using the RequestAsync function from HttpService, tho I constantly get the error “411 Length Required”.

I tried to fix this by adding [“Content-Length”] to the Header, but then it told me that it is not allowed to use this as a Header.

Is there any reason why this is restricted? I used a test website which sent the same request (link), and it automatically filled in Content-Length (without me putting this in the header). So like is there a way to bypass this, or any reason why this isn’t a thing in first place?

Are you adding a body along with your request? Content-Length should be automatic.

1 Like

FIXED:

For anyone else struggling with this, add “Content-length” to the body, like so:

local post = HttpService:RequestAsync( {
	Method = "PUT",
	Url = "URL",
	Headers = {
		["Content-Type"] = "application/json",
	},
	Body = HttpService:JSONEncode({
		["Content-Length"] = 0
	})
})
1 Like

I don’t think this is automatic tho, I fixed it by adding the line to the body itself.