|
发表于 2009-7-26 17:44:56
|
显示全部楼层
luasocket示例
注意要用header信息冒充下,否则可能antirobot不回应 囧
获取http返回信息,按chunk存入res列表
concat后即为完整的返回信息大string
最后部分是按行拆分,然后打印
蓝色注释部分为存文件的方法
local header = {}
header['User-Agent'] = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; TencentTraveler 4.0; .NET CLR 2.0.50727)'
function RequestSend (url, savefile)
-- local f = io.output (savefile)
local res = {}
http.request{
url = url,
sink = ltn12.sink.table (res),
-- sink = ltn12.sink.file (f),
headers = header
}
local lines = utils.split (table.concat (res), '\n')
for k, v in pairs (lines) do
Note (k, " : ", string.len (v), " = ", v)
end
end |
|