-- Downloading data
function setup()
textData = nil
params={}
headers={}
headers["Host"]="new.mcko.ru"
params["method"]="GET"
-- changing useragent does not solve the problem...
params["useragent"]= "Mozilla/4.0(compatible; MSIE 7.0b; Windows NT 6.0)"
params["headers"]=headers
-- Request some data
http.request( 'http://new.mcko.ru',
didGetData, fail, params)
end
-- Our callback function
function didGetData( data, status, headers )
print(status..": ")
-- This line prints empty string
-- But I checked - server sends zipped data
print(data)
for k,v in pairs(headers) do print(k..": "..v) end
end
function fail(error)
print("error")
end
I don’t think the Base64 helps. I was just trying to see the string that was there. I’m still working on this. Anyone else have for knowledge on compression?
There is also the (reasonably unpleasant ) option of implementing gzip/deflate in pure lua
A quick google turned up a pure lua implementation (although may need some modification for codea) :
Please explain, how to use some of the choices you described.
First about Accept header. I tried to disallow that, but could not.
And that is the fastest way to solve the problem.
Second about pure lua. That will be slow, but enough for me, I think.
You were right. That code is not compiled by Codea…
I got in line
local crc32 = require “digest.crc32lua” . crc32_byte
error that that module not found.
How Can I add it to Codea?
How to use JavaScript fo my purpose?
I have no idea…
And finally yes, I have thoughs about writing main code in PHP
and then get Queries from Codea program and send to Codea the results only
from the php script.
But this does not seem to me a good Idea, because we need to organize special server - webpage for the program, and it will be difficult for many users…
The accept header is probably your best bet for a simple solution. Setting it up like so should tell the server you want plain text or HTML instead of gzipped (it actually says to the sever i only support/accept these formats of data)
local params ={ headers = {Accept="text/*, text/html"} }
local success = function() end
local fail = function() end
http.request("url",success,fail,params)
The other solutions i wouldn’t recommend unless you absolutely have to as there is considerably more work involved :). The pure lua one would need the “inflate” part of the algorithm to be extracted or its dependencies to be included with it in Codea. The JavaScript one is really just for a secondary reference. The same goes for the actual specs of gzip and the deflate algorithm, just for reference of how gzip works :).
-- Downloading data
function setup()
textData = nil
params={}
headers={}
headers["Host"]="new.mcko.ru"
params["method"]="GET"
headers["Accept"]="text/*, text/html"
params["headers"]=headers
-- Request some data
http.request( 'http://new.mcko.ru',
didGetData, fail, params)
end
-- Our callback function
function didGetData( data, status, headers )
print(status..": ")
print(data)
for k,v in pairs(headers) do print(k..": "..v) end
end
function fail(error)
print("error")
end
Having a look at this it seems to work just fine and the accept headers are completely unnecessary also. It actually seems to be print is not printing the data which is 26611 characters long. Try this for the didgetdata function I’m just printing the first 255 characters.
function didGetData( data, status, headers )
print(status..": ")
local count =#data
print(count)
print(string.sub(data,1,255))
for k,v in pairs(headers) do print(k..": "..v) end
end