This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Reading HTTP Response Headers?
Started by TehTotalPwnage, 22 December 2015 - 01:42 AMPosted 22 December 2015 - 02:42 AM
Title basically says it all. If I make an HTTP request in ComputerCraft, how can I get any headers that it returns such as the Location header for 301 redirects, the content length, and so on.
Posted 22 December 2015 - 02:53 AM
Posted 22 December 2015 - 03:40 AM
As far as I know, getResponseCode() only returns the HTTP status code such as 200 OK or 301 Moved Permanently, but doesn't display the rest of the response headers.
Posted 22 December 2015 - 04:27 AM
In that case, there is no way to get any other response header.
Posted 22 December 2015 - 04:37 AM
I've got a memory that the betas for CC 1.76 can do some extra stuff in this area? The http API isn't something I've put a lot of research into.
Posted 22 December 2015 - 12:32 PM
For content length, just do the following:
f.readAll returns the text on the page you requested.
and "#" return the number of elements in an object.
local f = http.get(url)
local length = #f.readAll()
f.readAll returns the text on the page you requested.
and "#" return the number of elements in an object.
Posted 22 December 2015 - 03:30 PM
I'd point out fs.getSize before such awkward workarounds.
Posted 22 December 2015 - 03:55 PM
I'd point out fs.getSize before such awkward workarounds.
It is for http requests, not for the filesystem.
Posted 22 December 2015 - 05:00 PM
So it is. Which makes your suggestion even worse, because now the content must be fetched a second time to do anything useful with it. At least suggest saving it to a separate string before finding the length!