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.
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
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