local http=require("socket.http");

  local request_body = [[login=user&password=123]]
local response_body = {} local res, code, response_headers = http.request{
url = "http://httpbin.org/post",
method = "POST",
headers =
{
["Content-Type"] = "application/x-www-form-urlencoded";
["Content-Length"] = #request_body;
},
source = ltn12.source.string(request_body),
sink = ltn12.sink.table(response_body),
} print(res)
print(code) if type(response_headers) == "table" then
for k, v in pairs(response_headers) do
print(k, v)
end
end print("Response body:")
if type(response_body) == "table" then
print(table.concat(response_body))
else
print("Not a table:", type(response_body))
end

http://pyfpdf.readthedocs.io/projects/wiki/en/latest/language/lua/http.html

Lua使用luasocket http请求例子的更多相关文章

  1. Lua面向对象之一:简单例子

    1.Lua面向对象实现步骤 ①创建一个全局表(称之为元表) ②设置这个元表的__index值(值通常为元表自己,这样就能通过__index查找到对应的属性和方法) __index 赋值其实是一个fun ...

  2. 【原创】大叔经验分享(77)openresty(nginx+lua)发http请求

    openresty(nginx+lua)发http请求 利用location+proxy_pass间接实现 location ^~ /test/http { internal; proxy_pass ...

  3. 使用nodegrass简单封装http请求例子

    1.项目中经常性的使用http发送请求处理数据.而大部分请求方式为get和post,于是对http请求进行封装,提供代码的利用率. 2.nodegress是nodejs的一个请求工具. 具体步骤及代码 ...

  4. Lua协程的一个例子

    很久没记录笔记了,还是养成不了记录的习惯 下面是来自 programming in lua的一个协程的例(生产者与用户的例子) 帖代码,慢慢理解 -- Programming in Lua Corou ...

  5. 【HttpClient】一个http_post请求例子

    package httpclient.httpclient; import java.io.IOException; import org.apache.http.Header; import org ...

  6. WCF服务支持HTTP(get,post)方式请求例子

    https://www.cnblogs.com/li150dan/p/9529413.html /// <summary> /// Http Get请求 /// </summary& ...

  7. c# 模拟get请求例子,演示Session会话状态。

    创建一个控制台 程序: using System; using System.Collections.Generic; using System.IO; using System.IO.Compres ...

  8. perl6 Net::HTTP 发送任意 url 请求例子

    只做个笔记, 用 HTTP::UserAgent 的话, url 中有特殊点的符号会请求不了, 用 Net::HTTP 能很好的发送请求. use Net::HTTP::GET; my $url = ...

  9. httpclient post请求例子(无参数名与带参数名的例子),多线程并发处理

    版本:4.1 带参数名的情况 HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url ...

随机推荐

  1. table 组件

    table 组件了解一下? https://juejin.im/post/5da925bdf265da5b5d205b3f?utm_source=gold_browser_extension

  2. Revealjs网页版PPT让你复制粘贴另类装逼,简洁优雅又低调,不懂编程也看过来

    Revealjs网页版PPT让你复制粘贴另类装逼,简洁优雅又低调,不懂编程也看过来 要了解一个新知识我们可以从三个方面入手:是什么,有什么用,怎么用.下面我们就从这三个方面进行讲解Reveal.js噢 ...

  3. Session是怎么实现的?存储在哪里?

    为什么有session? 首先大家知道,http协议是无状态的,即你连续访问某个网页100次和访问1次对服务器来说是没有区别对待的,因为它记不住你. 那么,在一些场合,确实需要服务器记住当前用户怎么办 ...

  4. Spring AOP 基于AspectJ

    简介 AspectJ是一个基于Java语言的AOP框架,Spring2.0以后新增了对AspectJ切点表达式支持.因为Spring1.0的时候Aspectj还未出现; AspectJ1.5中新增了对 ...

  5. opensuse安装Tomcat碰到的问题

    已经安装好JDE,并配置好环境变量 从官网下载Tomcat tar包,解压到用户目录,进入运行bin下的start.sh,显示运行成功,但是浏览器中输入localhost:8080连接不上 检查一番发 ...

  6. ubuntu下报错Sub-process /usr/bin/dpkg returned an error code (1)的解决方法

    cd /var/lib/dpkg sudo mv info info.bak #即备份一个info sudo mkdir info #新建一个新的info目录 然后采用以下命令重装那些出错的软件包 s ...

  7. C#实现的对文件的重命名

    如下C#实现对文件的重命名的方法需要传入三个string类型的参数,分别是源文件的文件目录.目的文件目录和重命名的文件名称,实现代码如下: public ExecutionResult FileRen ...

  8. ReactNative: 自定义ReactNative API组件

    一.简介 在前面介绍了很多ReactNative中UI组件和API组件,这些都是Facebook团队封装好的基础组件,开发者可以直接使用.然而,在实际的开发过程中,面对复杂的需求,此时原生的Nativ ...

  9. map set vector用法小总结

    1.Map 定义 #include<map> map<string,bool> mp; 插入 mp[s]=; mp.insert(make_pair(s,)); 输出 cout ...

  10. FFT 入门

    推荐博客 :https://oi.men.ci/fft-notes/ 卷积的理解 : https://www.zhihu.com/question/22298352?rf=21686447 题目链接 ...