繁体   English   中英

Luasec Luasocket https.request与用户代理并返回正文

[英]Luasec Luasocket https.request with user agent and return body

我想使用LuaSec使用自定义用户代理进行https.request。 我已经尝试过这里描述的方法:

https://github.com/brunoos/luasec/wiki/LuaSec-0.4#httpsrequesturl---body

但是我不知道如何将http标头传递给此函数,以避免避免将响应正文设置为数字1,如下所述:

如果url是一个 ,则该函数返回相同的结果,但响应的正文由值1代替。

 local headers = {
    ["user-agent"] = "My User Agent",
}

local r, c, h, s = _https.request {
    url = url,
    method = method,
    headers = headers,
}
-- r is 1, no the response body!

如果我将请求更改为

_https.request("https://my-site-goes-here.com/")

我得到了响应主体,但是之后我不能再设置用户代理了。

谢谢你的帮助!

如果指定表,则成功时第一个return元素始终为 1 要接收实际数据,您还必须指定接收 ,接收到的数据将存储到该接收器。 例如:

local chunks = {}
local r, c, h, s = _https.request {
    url = url,
    method = method,
    headers = headers,
    sink = ltn12.sink.table(chunks)
}
local response = table.concat(chunks)

现在您可以从变量response检索response

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM