糖果实验室杂货铺

Candy Lab

Simple HTTP

2 years 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
23
24
25
26
local http = require("lapis.nginx.http")

local app = lapis.Application()

app:get("/", function(self)
  -- a simple GET request
  local body, status_code, headers = http.simple("http://leafo.net")

  -- a post request, data table is form encoded and content-type is set to
  -- application/x-www-form-urlencoded
  http.simple("http://leafo.net/", {
    name = "leafo"
  })

  -- manual invocation of the above request
  http.simple({
    url = "http://leafo.net",
    method = "POST",
    headers = {
      ["content-type"] = "application/x-www-form-urlencoded"
    },
    body = {
      name = "leafo"
    }
  })
end)

糖果实验室

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

Write a Comment