This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
snoble2022's profile picture

I'm getting errors in http that use to not happen?

Started by snoble2022, 22 November 2012 - 06:00 AM
snoble2022 #1
Posted 22 November 2012 - 07:00 AM
Hello,

I tried this but it says ""… Well acctually it says nothing. But heres the code:

--This is an api BTW --
function downloadFiles(sUrl)
   local file = http.get("http://pastebin.com/raw.php?i="..sUrl)
   local hFile = io.open("WebData", "w")
   hFile:write(file)
   hFile:close()
end

I've also tried this:

function downloadFiles(sUrl)
  fs.delete("WebData")
  shell.run("pastebin", "get", sUrl, "WebData")
end

Please help! THANKS!!!
Cranium #2
Posted 22 November 2012 - 07:13 AM
You forgot to read from the website.

function downloadFiles(sUrl)
   local file = http.get("http://pastebin.com/raw.php?i="..sUrl)
   local siteFile = file.readAll() --just need to read the website
   file.close()
   local hFile = io.open("WebData", "w")
   hFile:write(siteFile)
   hFile:close()
end
snoble2022 #3
Posted 22 November 2012 - 07:17 AM
Thank you soooo much cranuim. And derp on my part. +1
RemoteMine #4
Posted 22 November 2012 - 09:21 PM
I would add a save location too. Just incase you want it, here.

function downloadFiles(sUrl, sFile)
   local file = http.get("http://pastebin.com/raw.php?i="..sUrl)
   local siteFile = file.readAll() --just need to read the website
   file.close()
   local hFile = io.open(sFile, "w")
   hFile:write("--Downloaded by snoble2022's pastebin function.")
   hFile:write(siteFile)
   hFile:close()
end
Pretty sure that will work. You might need or not need the, separating the 2 parameters in
function downloadFiles(sUrl, sFile)
KillaVanilla #5
Posted 22 November 2012 - 09:25 PM
I would add a save location too. Just incase you want it, here.

function downloadFiles(sUrl, sFile)
   local file = http.get("http://pastebin.com/raw.php?i="..sUrl)
   local siteFile = file.readAll() --just need to read the website
   file.close()
   local hFile = io.open(sFile, "w")
   hFile:write("--Downloaded by snoble2022's pastebin function.")
   hFile:write(siteFile)
   hFile:close()
end
Pretty sure that will work. You might need or not need the, separating the 2 parameters in
function downloadFiles(sUrl, sFile)

This will work, and yes you do need the comma.
RemoteMine #6
Posted 22 November 2012 - 09:29 PM
Just as I suspected, damn brain, tut tut tut.