Code: Select all
bytesSent = socket:send(requeststring)
bytesSent = socket:send("User-Agent: SOBrowser\r\n")
bytesSent = socket:send("Host: so.ikhoefgeen.nl\r\n\r\n")
"GET /?id=1 HTTP/1.0 \r\n"
"GET /?test=2 HTTP/1.0\r\n"
For those interested, here's the full function I use for this:
Code: Select all
function GetFile(requeststring,Method,storestring)
print("Getfile")
buffer = nil
data = nil
filestart =nil
TimeOut = 0
if RequestOut then print(requeststring) end
bytesSent = socket:send(requeststring)
bytesSent = socket:send("User-Agent: SOBrowser\r\n")
bytesSent = socket:send("Host: so.ikhoefgeen.nl\r\n\r\n")
while true do
buffer = socket:recv()
if string.len(buffer) > 0 then
print("buffer filled",buffer)
if filestart~=1 then
--print(buffer)
if string.find(buffer, "\r\n\r\n") then
data = string.sub(buffer,string.find(buffer, "\r\n\r\n")+4)
filestart = 1
end
else
data = data..buffer
--print(data)
--file:write(buffer)
end
else -- probably end of transfer
TimeOut = TimeOut + 1
if TimeOut == 50 then
if data then
if DataOut == 1 then print(data) end
if Method == 1 then
assert(loadstring(storestring.."="..data))()
elseif Method == 2 then
file = io.open(storestring,"w+")
file:write(data)
file:close()
end
GotData = true
end
--print(1,LevelData)
break
end
end
if Controls.read():start() then break end
--screen.waitVblankStart()
end
end
Code: Select all
while not GotData do
GetFile("GET /?test=2 HTTP/1.0\r\n",1,"LevelData")
end