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. map类型转为实体类

    BareBaseRequest fromJson = JSON.parseObject(JSON.toJSONString(map), BareBaseRequest.class);

  2. 【转】DB2数据库编目的概念以及对其的正确解析

    此文章主要向大家描述的是DB2数据库编目的概念以及对DB2数据库编目的概念的正确理解,在DB2中编目(catalog)这个单词看似很难理解,我自己当初在学习DB2数据库的时候也常常被这个编目搞的很不明 ...

  3. windows创建git并连结github

    1.下载跟自己系统相对应的git版本 2.默认安装 3.绑定用户 git config --global user.name ""git config --global user. ...

  4. react入门(六):状态提升&context上下文小白速懂

    一.状态提升 使用 react 经常会遇到几个组件需要共用状态数据的情况.这种情况下,我们最好将这部分共享的状态提升至他们最近的父组件当中进行管理. 原理:父组件基于属性把自己的一个fn函数传递给子组 ...

  5. Ubuntu 19.10 安装 jupyter

    安装pip3 ubuntu 19.10 已经没有python了,取代的是python3. 执行sudo apt install python3-pip安装pip3 安装jupyter 执行sudo p ...

  6. 重拾c++第二天(4):复合类型

    1.定义:种类 数组名[元素个数] = {元素1,...,元素n} ,或者直接赋值:数组名[元素位置] = 值; 2.部分初始化,其他全为0,可以就定义一个0,这样得到0数组(或者就一个{},别的啥也 ...

  7. window 10 安装Oracle odac 64位

    下载地址:https://www.oracle.com/cn/database/technologies/windows/downloads.html 可以下载XCopy版,也可以继续往下看下载安装文 ...

  8. MySQL查询基础

    MySQL查询 DQL(Data Query Language ) 1.排序查询 # 语法: select 字段 from 表名 order by 字段1 [降序/升序],字段2 [降序/升序],.. ...

  9. background-position和position

    1.background-position:表示背景定位的属性.描述属性值时,有两种方式:一是像素描述:而是单位描述. (1)像素描述: 格式如下: background-position:向右偏移量 ...

  10. crawler碎碎念6 豆瓣爬取操作之获取数据

    import requests from lxml import etree s = requests.Session() for id in range(0,251,25): url ='https ...