用lua访问http

Debug posted @ 2013年3月21日 13:45 in 代码片段 with tags http Lua , 18219 阅读

首先你需要lua, 这自不必说。

然后你需要luasocket。 下载地址http://files.luaforge.net/releases/luasocket/luasocket

不过luasocket好像很久没有更新了,也只支持到lua5.1。

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

function http.get(u)
   local t = {}
   local r, c, h = http.request{
      url = u,
      sink = ltn12.sink.table(t)}
   return r, c, h, table.concat(t)
end

url = "http://www.baidu.com"
r,c,h,body=http.get(url)
if c~= 200 then
    return
end
print(body)
dfdf 说:
2019年1月28日 18:53

CGC Jhanjeri is one of the best colleges in the North India and we are providing the best quality of education in various courses.Over the last few decades, engineering as a profession has seen vast expansion.
best engineering college in chandigarh
best engineering college in north india
Private management college in punjab
civil engineering college in mohali
CGC campus
best agriculture college in chandigarh
college with best placement in punjab

Mark 说:
2019年2月07日 18:05

Our academic pursuits, along with a range of extracurricular activities, help in honing a child's skills and ensuring that he/she grows to be a mature and responsible citizen.<br>
<a href="http://www.gdgoenkanoida.edu.in">Best school in greater noida</a>

Mark 说:
2019年2月07日 18:05

Our academic pursuits, along with a range of extracurricular activities, help in honing a child's skills and ensuring that he/she grows to be a mature and responsible citizen.
[url=http://www.gdgoenkanoida.edu.in]best school in greater noida[/url]

Mark 说:
2019年2月07日 18:07

Our academic pursuits, along with a range of extracurricular activities, help in honing a child's skills and ensuring that he/she grows to be a mature and responsible citizen.
Best school in greater noida

Vig 说:
2019年2月07日 18:08

Moonlight Films and Theatre Studio operates under the Moonlight Films and Theatre Society , a non-profit association whose goals are to spread knowledge of and interest in theatrical and media arts through education.
Acting school in delhi

Hot Shapers Belt in 说:
2019年3月11日 03:47

You completely match our expectation and the variety of our information. <a href="https://www.telebrand.pk/product/hot-shapper-belt-in-pakistan/">Hot Shapers Belt in Pakistan</a>

Assignment help onli 说:
2019年3月15日 18:20

Many students face the problem of stress in college. Whether it is because of social anxiety, or not being able to clear exam etc. Most of the times, students get stressed due to their piled up assignments. If it is with you also then you might seek for Assignment Help.

Assignment Help UK 说:
2019年3月28日 17:09

My Assignment Services is one such Assignment Help UK provider which provides a helping hand to all your academic related queries.

Essay Help Australia 说:
2019年3月28日 17:09

Many students see that Essay Help Australia experts are proficient in writing your assignments but no one wonders the reason behind it.

Resume Writing Servi 说:
2019年3月28日 17:10

You can also contact some real time Resume Writing Services experts to assist you with the following topics.

assignment help uk 说:
2019年4月15日 17:16

We offer top-quality assignment help to students in UK. Assignment help uk is number 1 assignment help services like as manage the assignments in college and schools, in UK.

Tech Support 说:
2019年4月22日 18:22

If you want to fix Sage 50 problems then you can get in touch with Peachtree support get in touch with extensive variety at at any initiatives and if the big mistake carries on weblink with IMPCsupport.

http://www.advisorexpert.co.uk/sage-support-phone-number/

Gos 说:
2019年4月23日 19:38

The Health system is created in a proficient way of expanding the network in the multispecialty services. With the ever-growing population, the hospital has announced many ambitious plans that have ultimately lead to the excellence.
[url="http://www.goswamihospital.com"]multispeciality hospital in hisar[/url]
And
[url="http://www.tsushisar.edu.in"]best school in barwala[/url]

Gos 说:
2019年4月23日 19:40

The Health system is created in a proficient way of expanding the network in the multispecialty services. With the ever-growing population, the hospital has announced many ambitious plans that have ultimately lead to the excellence.
multispeciality hospital in hisar
And
best school in barwala

private boat tours a 说:
2019年4月24日 19:39

This site is really a gift to programmers. It's a pool of code to explore. It supports me a lot in my career. This site is very helpful for students too. We can learn a lot from here. The codes are so simple and efficient. I thank the brains behind this site.

marry 说:
2019年5月01日 12:37

Packers and Movers Bangalore are running in relocation field from coon’s age and serving us with the help of highly professional and trained team and to make our relocation more effective and efficient they are loaded with updated relocation equipment and techniques. Packers and Movers Bangalore is from 4 elite moving company and certified with IBA for relocation work. Packers and Movers Bangalore #charges are reasonable and genuine and because of this quality they also are known as #cheap and #best Packers and Movers in Bangalore.

<a href="https://assuremoving.in/packers-and-movers-gurgaon/">Packers and Movers Gurgaon,Gurgaon Packers and Movers</a>

ahc 说:
2019年7月18日 15:19

Provides multiple learning environment of International standard with holistic system of education at an affordable cost for the successful life of young generation.
best agriculture college in dehradun
Paramedical College india
best B.Ed. college in dehradun

dcb 说:
2019年8月14日 15:33

Welcome to the world of gaming, where life is fast paced and interesting. There is always an adventure waiting for you online.
csgo ranked accounts
csgo bundles accounts


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter