Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
api:internet [2019/06/15 09:24]
payonel
api:internet [2019/11/29 23:06]
jab [Internet API]
Line 30: Line 30:
 handle:​close()  ​ handle:​close()  ​
 ``` ```
 +If you need the HTTP response code, message, and headers, they are retrieved from the internal object, which is stored in the metatable of the returned object. 
 +```lua 
 +-- https://​github.com/​kikito/​inspect.lua/​blob/​master/​inspect.lua 
 +local inspect = require("​inspect"​) 
 +local internet = require("​internet"​) 
 +  
 +local handle = internet.request("​https://​www.google.com"​) 
 +local result = ""​ 
 +for chunk in handle do result = result..chunk end 
 +-- Print the body of the HTTP response 
 +-- print(result) 
 +  
 +-- Grab the metatable for the handle. This contains the 
 +-- internal HTTPRequest object. 
 +local mt = getmetatable(handle) 
 +  
 +-- The response method grabs the information for 
 +-- the HTTP response code, the response message, and the 
 +-- response headers. 
 +local code, message, headers = mt.__index.response() 
 +print("​code = "​..tostring(code)) 
 +print("​message = "​..tostring(message)) 
 +print(inspect(headers)) 
 +```
  
 This is an example of a basic IRC bot that echos back what you say to it, using the sockets in the internet api. This is an example of a basic IRC bot that echos back what you say to it, using the sockets in the internet api.