Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how to detect if a url is invalid? (httpservice)

I don't really need to provide a script for this, but here's an example:

url = "url.com"
http = game.HttpService

if not http:GetAsync(url) then
print("invalid!")
else
print("valid!")

you get the point. My problem is that whatever way i try and do this, it always returns a http not found (404) even if i'm using 'if not'. Would there be any way to detect an invalid url?

thanks!

2 comments

0

Do you mean to check the status code returned from the http request?

0

yes

2 answers

✓ Accepted answer

After messaging Seranok, he told me:

There is currently no way to check the status code of the response. At some point in the future we may add this functionality but not in the foreseeable future. If you want to handle errors you can use pcall.

To use pcall, do this:

function getData()
	--request here
	return --return the response
end
success, responseBody = pcall(getData)
if success then
	--do something with responseBody
else
	print("There was an error")
end

From what I'm getting out of what you're asking, the easiest way it seems to do this, would be to search for 404 on the page, and if it's there, then it prints "Invalid!" Hope this helped. If not feel free to keep asking me for help until we solve your problem so it does work.

5 comments

0

use comments then, please delete this answer because this isn't an 'answer'

0

It would be nice if we could moderate answers.

0

ok

0

This is an answer, and a good answer for this specific question.

0

I don't know how you don't think this is an answer Aviator.

This discussion is preserved as it was. New answers, comments, and votes are closed.