3️Lua--HTTP模块
导入模块
local http = require("http")
GET方式 HTTP 请求头
local response, error_message =
http.request(
"GET",
"https://cloud.ibm.com/login",
{
headers = {
["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36",
["Accept"] = "*/*"
}
}
)
local result = response.body --字符串类型 尽量不要获取流类型的请求
GET方式 简略模式
local url = string.format("http://192.168.198.155:8097/guess/%d.json", num)
local response, error_message = http.request("GET", url)
local music = response.body
POST方式 HTTP 请求头
local response, error_message =
http.request(
"POST",
"https://cloud.ibm.com/login/doLogin",
{
headers = {
["Referer"] = "https://cloud.ibm.com/login",
["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36",
["Content-Type"] = "application/json"
},
body = [[{"username":"123@qq.com","password":"1231","realm":"IBMid","iamRegionalEndpoint":"https://identity-3.us-south.iam.cloud.ibm.com","postLoginConsolePage":""}]]
}
)
local result = response.body --取得返回数据
Last updated