Difference between revisions of "Http.checkURL"

From ComputerCraft Wiki
Jump to: navigation, search
(Add http.checkURL page)
 
(reformatted)
 
Line 3: Line 3:
 
|name=http.checkURL
 
|name=http.checkURL
 
|args={{type|string}} url
 
|args={{type|string}} url
|returns={{type|boolean}} success, {{type|string}} message
+
|returns={{type|boolean}} success [, {{type|string}} message]
 
|api=HTTP
 
|api=HTTP
 
|addon=ComputerCraft
 
|addon=ComputerCraft
|desc=Validates a URL, checking it is in the correct format and it the website is on the whitelist. If the URL is not valid then the second return value will be an appropriate error message.
+
|desc=Validates a URL, checking it is in the correct format and the website is on the HTTP whitelist. If the URL is not valid then the second return value will be an appropriate error message.
 
|examples=
 
|examples=
 
{{Example
 
{{Example
 
|desc=Validates a URL and errors if it is invalid.
 
|desc=Validates a URL and errors if it is invalid.
|code=local success, message = '''http.checkURL("http://example.com")'''
+
|code=local success, message = '''http.checkURL( "http://example.com" )'''
 +
 
  if not success then
 
  if not success then
   error("Invalid URL: " .. message)
+
   [[error]]( "Invalid URL: " .. message )
 
  end
 
  end
 
}}
 
}}
 
{{Example
 
{{Example
 
|desc=Various outputs of http.checkURL.
 
|desc=Various outputs of http.checkURL.
|code=http.checkURL("http://example.com") -- true
+
|code='''http.checkURL( "http://example.com" )''' ''-- true''
  http.checkURL("example.com") -- false, URL malformed
+
  '''http.checkURL( "example.com" )''' ''-- false, URL malformed''
  http.checkURL("ftp://example.com") -- false, URL not http
+
  '''http.checkURL( "ftp://example.com" )''' ''-- false, URL not http''
 
}}
 
}}
 
}}
 
}}
  
 
[[Category:Lua_Core_Functions]]
 
[[Category:Lua_Core_Functions]]

Latest revision as of 20:38, 1 August 2015


Grid Redstone.png  Function http.checkURL
Validates a URL, checking it is in the correct format and the website is on the HTTP whitelist. If the URL is not valid then the second return value will be an appropriate error message.
Syntax http.checkURL(string url)
Returns boolean success [, string message]
Part of ComputerCraft
API HTTP

Examples

Grid paper.png  Example
Validates a URL and errors if it is invalid.
Code
local success, message = http.checkURL( "http://example.com" )

if not success then
  error( "Invalid URL: " .. message )
end



Grid paper.png  Example
Various outputs of http.checkURL.
Code
http.checkURL( "http://example.com" ) -- true
http.checkURL( "example.com" ) -- false, URL malformed
http.checkURL( "ftp://example.com" ) -- false, URL not http