HTTP Requests
Fetch web resources.
The socket.http Module
LuaSocket ships a high-level HTTP client in socket.http. It builds on raw TCP but handles request formatting, headers, and chunked decoding for you.
It speaks HTTP/1.1 over plain TCP. For HTTPS you need the companion ssl.https module from LuaSec.
local http = require("socket.http")
print(http.PORT)A Simple GET
The simplest form takes a URL and returns the body, status code, response headers, and status line.
A status code of 200 means success. Any nil body indicates a transport-level failure rather than an HTTP error.
local http = require("socket.http")
local body, code, headers = http.request("http://example.com/")
print(code, #body)All lessons in this course
- TCP Basics
- Building a Client
- Building a Server
- HTTP Requests