Socket – Lua Socket.http Receiver Parameters

I’m trying to communicate with Lua’s server to verify user identity. This is how my request function looks like:

 function http.send(url)
local req = require("socket.http")
local b, c, h = req.request{
url = url,
redirect = true
}
return b
end

However, I noticed that the data was discarded because I did not provide a sink parameter. I want to be able to download the data as the whole The string is returned instead of being downloaded to a file/table. What should I do?

You can use ltn12.sink.table to collect the results one by one The given table. Then you can use table.concat to get the result string.

The example used from the ltn12.sink documentation:

-- load needed modules
local http = require("socket.http")
local ltn12 = require("ltn12")

-- a simplified http. get function
function http.get(u)
local t = {}
local status, code, headers = http.request{
url = u,
sink = ltn12.sink.table(t)
}
return table.concat(t), headers, code
end

Me I am trying to communicate with Lua’s server to verify user identity. This is how my request function looks like:

function http.send(url)
local req = require("socket.http")
local b, c, h = req.request{
url = url,
redirect = true
}
return b
end

However, I noticed that the data was discarded because I did not provide a sink parameter. I want to be able to return the downloaded data as a whole string instead of downloading to a file/table. what should I do?

You can use ltn12.sink.table to collect the results into a given table one by one. Then you can use table. concat to get the result string.

The example used from the ltn12.sink document:

-- load needed modules
local http = require("socket.http")
local ltn12 = require("ltn12")

-- a simplified http.get function
function http.get(u )
local t = {}
local status, code, headers = http.request{
url = u,
sink = ltn12.sink.table(t)
}
return table.concat(t), headers, code
end

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3265 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.