0

我试图使用 LibCurl 登录。实际上我在 Lua 中使用 LuaCurl 绑定 libCurl。我指的是这个网页:http ://www.hackthissite.org/articles/read/1078

我试过这个:

> require("libcurl")
> c=curl.new()
> c:setopt(curl.OPT_USERAGENT,"Mozilla/4.0")
> c:setopt(curl.OPT_AUTOREFERER,true)
> c:setopt(curl.OPT_FOLLOWLOCATION,true)
> c:setopt(curl.OPT_COOKIEFILE,"")
> c:setopt(curl.OPT_URL,"https://www.chase.com")
> res=c:perform()

但是在最后一次操作之后,程序就像在等待什么一样卡住了。我在这里做错了什么?

谢谢

4

1 回答 1

0

我试过你的程序,它似乎工作正常。我得到的是给定站点的内容被抽到stdout. 看来你只是有网络问题......

如果您想将整个输出捕获为字符串并在以后处理它,您必须提供一个回调,使用OPT_WRITEFUNCTION该回调将使用您可以保存的更多数据调用。这是我如何GET在我的简单网络挖掘工具箱WDM中实现该方法的简化版本。

local c = curl.new()
... 
function get(url)
    c:setopt(curl.OPT_URL,url)
    local t = {} -- output will be stored here
    c:setopt(curl.OPT_WRITEFUNCTION, function (a, b)
        local s
        -- luacurl and Lua-cURL friendly way
        if type(a) == "string" then s = a else s = b end
        table.insert(t, s) -- store this piece of data
        return #s
    end)
    assert(c:perform())
    return table.concat(t) -- return the whole content
end
于 2013-02-07T21:28:16.137 回答