糖果实验室杂货铺

Candy Lab

用luasocket发送HTTP请求

4 months ago 0

代码如下:

None
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
local lua_script = [[
GET /puku/pic/2017-06-26/8328.html HTTP/1.1
Content-Length: 0
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
Host: www.abc.com
]]

local socket = require("socket")
local host = "www.baidu.com"
local file = "/" 
local sock = assert(socket.connect(host,80))
sock:send("GET "..file.."HTTP/1.0\r\n\r\n")

repeat 
    local chunk, status, partial = sock:receive(1024)
    print(status)
    print(chunk or partial)
--until status ~= "closed"
until status == "closed"
sock:close()

--print(lua_script)

糖果实验室

Openresty中文编程网
IKBC经典机械键盘
机械键盘领券优惠购买

Write a Comment