[英]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.