So I have been working with network.download() for the first time and was having a good deal of success until I removed all my files from my server to test what would happen. Here is sample code:
[lua]if require(“socket”).connect(“www.scottadelman.com”, 80) == nil then
print(“No INTERNET connection – Use Current Database”)
else
print(“getting for the first time”)
local function networkListener( event )
if ( event.isError ) then
print( “Network error!”)
elseif ( event.phase == “ended” ) then
print(event.status)
if event.status >= 200 and event.status < 300 then – file exists. call the function to download it.
network.download( “http://www.scottadelman.com/stored/ztp/banners.db”, “GET”, downloadResponse , “banners.db”, system.CachesDirectory )
else – file does not exist. call the function to get it created and then download it.
print(“FILE NOT ON SERVER”)
end
end
end
network.request( “http://www.scottadelman.com/stored/ztp/banners.db”, “HEAD”, networkListener )
end[/lua]
The print(event.status) returns with “200” even though the file does not exist on the server. It then puts this in the banners.db file and saves it causes lots of errors:
[lua]
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml” xml:lang=“en”>
<head>
<title>404 - Page Not Found</title>
<meta http-equiv=“content-type” content=“text/html; charset=UTF-8” />
<meta name=“robots” content=“noarchive” />
<link rel=“shortcut icon” href=“http://www3.dragndropbuilder.com/developer/none.ico” />
<style type=“text/css”>
body {
background: url(http://www3.dragndropbuilder.com/images/404background.jpg);
font-family: Helvetica, arial, sans-serif;
color: #ccc;
}
.alert-container {
background: url(http://www3.dragndropbuilder.com/images/404_textbox.png);
width: 918px;
height: 142px;
margin: 82px auto 0px;
}
.alert-inner {
padding: 24px 0px 0px 209px;
}
.alert-heading {
font-size: 50px;
font-weight: bold;
line-height: 50px;
}
.alert-subheading {
margin-top: 8px;
font-size: 28px;
line-height: 28px;
}
.redirect {
width: 918px;
margin: 24px auto 0px;
font-size: 14px;
line-height: 14px;
text-align: center;
}
.redirect a {
color: #ffb300;
text-decoration: none;
}
</style>
</head>
<body>
<div class=“alert-container”>
<div class=“alert-inner”>
<div class=“alert-heading”>404 - Page Not Found</div>
<div class=“alert-subheading”>Sorry, the page you are looking for does not exist</div>
</div>
</div>
<div class=“redirect”>Please check the URL. Otherwise, <a href=’/’>click here</a> to be redirected to the homepage.</div>
</body>
</html>
[/lua]
Why is this happening and what can I do?
Thanks,
Scott