Ubuntu / Openwrt使用lua发送http和https请求

news/2024/7/8 1:09:29 标签: http, ubuntu, lua
http://www.w3.org/2000/svg" style="display: none;">

Ubuntu / Openwrt使用lua发送httphttps请求

  • 1、Ubuntu配置以支持lua发送httphttps请求
    • 1.1、配置apt镜像源
    • 1.2、安装相关lua关联包
  • 2、Openwrt配置menuconfig支持lua发送httphttps请求
    • 2.1、配置menuconfig
  • 3、Ubuntu / Openwrt 使用lua发送httphttps请求
    • 3.1、测试发送http请求
    • 3.2、测试发送https请求

luahttphttps_1">1、Ubuntu配置以支持lua发送httphttps请求

1.1、配置apt镜像源

Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 6.5.0-41-generic x86_64)

链接: https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.6c1a1b117VwAM7

sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak

将下面的ubuntu 22.04 LTS (jammy) 配置配置到这个源文件中
sudo mv /etc/apt/sources.list

ubuntu 22.04 LTS (jammy) 配置如下

deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse

lua_34">1.2、安装相关lua关联包

sudo apt update
sudo apt install -y lua5.3
lua -v
sudo apt install -y liblua5.3-dev

sudo apt install -y luarocks
sudo luarocks install luasocket

luahttphttps_48">2、Openwrt配置menuconfig支持lua发送httphttps请求

2.1、配置menuconfig

配置选中 Languages -> Lua -> <*> luarocks 以支持https。

luahttphttps_57">3、Ubuntu / Openwrt 使用lua发送httphttps请求

http_59">3.1、测试发送http请求

local http = require("socket.http")

local url = "http://data-studio.gds.org.cn/Data/NewGtin"
local resp, code, headers, status = http.request(url)

if code == 200 then
    print(resp)
else
    print("Request failed with status code: " .. code)
end

https_74">3.2、测试发送https请求

lua">local http = require "socket.http"
local ssl = require "ssl.https"

local url = "https://www.baidu.com"
local headers = {}

-- 设置 HTTPS 选项
local options = {
   protocol = "TLSv1_2",
   verify = false,
}

-- 发送 HTTPS GET 请求
local response, status_code, response_headers = ssl.request({
   method = "GET",
   url = url,
   headers = headers,
   options = options,
})

if status_code == 200 then
   print(response)
   print(status_code)
   print(response_headers )
else
   print("Request failed with status code: " .. status_code)
end

http://www.niftyadmin.cn/n/5535974.html

相关文章

使用Java实现魔兽争霸3冰封王座联网

作者&#xff1a;cloudy491 顺便吆喝一声&#xff0c;如果你计算机、软件工程、电子等相关专业本科及以上学历&#xff0c;欢迎来共事。前端/后端/测试等均可投→技术大厂机会。 背景 自己实现搭建网络&#xff0c;在非同一个局域网下也可以玩魔兽争霸3冰封王座。一般我们是通…

C#——Path类详情

Path类 在C#中&#xff0c;文件和目录的操作是编程中常见的需求&#xff0c;而.NET Framework为我们提供了一个名为Path的类&#xff0c;用于进行文件的路径操作。 Path常用方法 相对路径转为绝对路径GetFullPath(string relativePath) string relativePath "..\\exam…

C++指针内存分配与释放

文章目录 指针分配与释放 &#xff1a;C new/delete VS C malloc/freeC new/deleteC malloc/free 指针销毁智能指针 指针分配与释放 &#xff1a;C new/delete VS C malloc/free new&#xff1a;分配内存、调用类的构造函数。delete&#xff1a;调用类的析构函数和释放内存&am…

xml_woarchive undefined symbol

最近在linux中编译一个自己写的老代码。是个C动态库。可以编译成功&#xff0c;但直到运行的时候才报 boost xml_woarchive undefined symbol. 解决的方法是在编译时要加上 wserialization 库。 注意&#xff0c;这个库有含 w 和不含 w 两个。在我这里需要使用含 w 的。 如果…

Rethinking Federated Learning with Domain Shift: A Prototype View

CVPR2023,针对分布式数据来自不同的域时,私有模型在其他域上表现出退化性能(具有域转移)的问题。提出用于域转移下联邦学习的联邦原型学习(FPL)。核心思想是构建集群原型和无偏原型,提供富有成效的领域知识和公平的收敛目标。将样本嵌入拉近到属于相同语义的集群原型,而…

8人团队历时半年打造开源版GPT-4o,零延迟演示引爆全网!人人可免费使用!

目录 01 Moshi 02 背后技术揭秘 GPT-4o可能要等到今年秋季才会公开。 然而&#xff0c;由法国8人团队开发的原生多模态Moshi&#xff0c;已经达到了接近GPT-4o的水平&#xff0c;现场演示几乎没有延迟&#xff0c;吸引了大量AI专家的关注。 令人惊讶的是&#xff0c;开源版的…

基于惯性加权PSO优化的目标函数最小值求解matlab仿真

目录 1.程序功能描述 2.测试软件版本以及运行结果展示 3.核心程序 4.本算法原理 5.完整程序 1.程序功能描述 基于惯性加权PSO优化的目标函数最小值求解matlab仿真。 2.测试软件版本以及运行结果展示 MATLAB2022A版本运行 &#xff08;完整程序运行后无水印&#xff09;…

【C++】 C/C++预处理器介绍

C预处理器&#xff08;Preprocessor&#xff09;是编译过程中的一个阶段&#xff0c;它在编译器进行实际编译之前对源代码进行处理。预处理器提供了一系列的指令&#xff0c;用于条件编译、文件包含、宏定义等操作。以下是一些常见的预处理器指令&#xff1a; 宏定义&#xff…