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

Github Raw Code Importing | Can't Get To Work

Started by DiabolusNeil, 14 November 2013 - 11:02 PM
DiabolusNeil #1
Posted 15 November 2013 - 12:02 AM
So… after about an hour of testing, I absolutely could not get this to work. I am trying to make a GitHub importing program, and it always returns an empty string. Could someone help me?

local function get(paste)
  local response = http.get(
  "http://raw.github.com/DiabolusNeil/testingRepo/master/"..textutils.urlEncode(paste)
  )
  if response then
	print("Success")
	local sResponse = response.readAll()
	response.close()
	return sResponse
  else
	print("Failed")
	response.close()
  end
end

local res = get("prog")
if res then
  wFile = fs.open("testing","w")
  wFile.write(res)
  print(res)
  wFile.close()
  print("Downloaded 'prog'")
else
  print("Error")
end

1. Yes, this is code from the Pastebin program. Like I said, I was experimenting.
2. I have tried this using Pastebin. It works perfectly.
3. That URL is valid. Try it yourself.
4. Pastebin code: STna0YV9

It always does this:
- Waits around a second, which seems like the program's actually receiving data.
- Prints out this message.
Edited on 14 November 2013 - 11:11 PM
distantcam #2
Posted 15 November 2013 - 12:41 AM
You need to use "https" instead of "http".

The GitHub servers return a 301 (Moved Permanently) status if you use http instead of https. Unfortunately the HTTP API does not follow 301's automatically.