Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago

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!

0
Do you mean to check the status code returned from the http request? addictedroblox1414 166 — 8y
0
yes V_ChampionSSR 247 — 8y

2 answers

Log in to vote
1
Answered by 8 years ago

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
Ad
Log in to vote
0
Answered by 8 years ago

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.

0
use comments then, please delete this answer because this isn't an 'answer' V_ChampionSSR 247 — 8y
0
It would be nice if we could moderate answers. TheDeadlyPanther 2460 — 8y
0
ok AcentrixTheYouTuber -8 — 8y
0
This is an answer, and a good answer for this specific question. OldPalHappy 1477 — 8y
0
I don't know how you don't think this is an answer Aviator. MrLonely1221 701 — 8y

Answer this question