Hello, I was making a function so that when I use HttpService, I don’t need to manually change https:// to http:// when a website doesn’t support it.
However, when using pcall(), the status code is stored but not the result.
Here’s my code:
function getData(ip)
local data
local state
local result
state, result = pcall(
function()
data = HttpService:GetAsync(string.format("https://%s/", ip))
end
)
print(result)
if tostring() == "false HttpError: SslConnectFail" then
local data = HttpService:GetAsync(string.format("http://%s/", ip))
elseif tostring(string.format("%s %s", state, result)) == "false HttpError: ConnectFail" then
print("Not an HTTP.S server!")
else
warn(string.format("Unknown error:\n%s", tostring(result)))
end
return data
end
you are missing the argument to the tostring() function in this line. you need to pass result as an argument.
function getData(ip)
local data
local state
local result
state, result = pcall(function()
data = HttpService:GetAsync(string.format("https://%s/", ip))
end)
print(result)
if tostring(result) == "false HttpError: SslConnectFail" then
data = HttpService:GetAsync(string.format("http://%s/", ip))
elseif tostring(string.format("%s %s", state, result)) == "false HttpError: ConnectFail" then
print("Not an HTTPS server!")
else
warn(string.format("Unknown error:\n%s", tostring(result)))
end
return data
end