HTTP 400 bad request

local http = game:GetService("HttpService")

local formData = {
	userID = 1790723680
}
local encodedData = http:JSONEncode(formData)

http:PostAsync(url, encodedData, Enum.HttpContentType.ApplicationJson)

This basically sends a post request to a website I made but it keeps erroring HTTP 400 Bad Request. I created my website with heroku, I dont wanna send the url since it has access to ranking members in a group.

Hey @OctaLua!

Could you help me out a little bit here and give me some more info?
I would like to see the error directly, knowing which line is erroring.

If you’re making a post request then receiving a 400 error most likely means it’s your website that’s not accepting it.

The PostAsync line is where the 400 comes from, I tried sending a post request to the exact same url with Python and it works so the problem comes from my Roblox Script

I see, another issue may be your URL.
Are you UrlEncode-ing it if it has special characters?

Now gives a different error

https%3A%2F%2Frankbot%2Eherokuapp%2Ecom%2Frank: Trust check failed

Alternatively, you could try using RequestAsync as it’s generally more reliable. Here’s the example code from the wiki.

-- Remember to set enable HTTP Requests in game settings!
local HttpService = game:GetService("HttpService")
 
local function request()
    local response = HttpService:RequestAsync(
		{
			Url = "http://httpbin.org/post",  -- This website helps debug HTTP requests
			Method = "POST",
			Headers = {
				["Content-Type"] = "application/json"  -- When sending JSON, set this!
			},
			Body = HttpService:JSONEncode({hello = "world"})
		}
	)
 
	-- Inspect the response table
	if response.Success then
		print("Status code:", response.StatusCode, response.StatusMessage)
		print("Response body:\n", response.Body)
	else
		print("The request failed:", response.StatusCode, response.StatusMessage)
	end
end
 
-- Remember to wrap the function in a 'pcall' to prevent the script from breaking if the request fails
local success, message = pcall(request)
if not success then
	print("Http Request failed:", message)
end

Note that you just gave the link, you might want to amend that reply.

1 Like

Hey, I have the same issue when my table that I send becomes too long, did you end up finding a solution?

@OctaLua