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

how do i view a webpage with http api

Started by dus998, 17 August 2012 - 01:06 AM
dus998 #1
Posted 17 August 2012 - 03:06 AM
i am trying to make http.request() show a webpage i tried the code on the wiki for http.request to show the source of a page but for some reason it stops at sourceText = code.readAll()

i am using this code (off the wiki)

http.request("http://pastebin.com/raw.php?i=Tk19jv43")
requesting = true
while requesting do
   local event, url, sourceText = os.pullEvent()
   if event == "http_success" then
	 respondedText = code.readAll()
	 print(respondedText)
	 requesting = false
   else
	 print("Server didn't respond.")
	 requesting = false
   end
end
the only thing i did was change the pastbin address to https://twitter.com/jeb_

the error its saying is twitter:6: attempted to index ? nil

i tried to make it print the sourceText variable in os.pullEvent() instead of the responded text and that returned https://twitter.com/jeb_ 131b835
ciba43 #2
Posted 17 August 2012 - 10:08 AM
What version of CC are you using? Https sites only work from 1.4
xuma202 #3
Posted 17 August 2012 - 10:15 AM
The variable code has never been initialized!


http.request("http://pastebin.com/raw.php?i=Tk19jv43")
requesting = true
while requesting do
   local event, url, sourceText = os.pullEvent()
   if event == "http_success" then
		 respondedText = sourceText.readAll()
		 print(respondedText)
		 requesting = false
   else
		 print("Server didn't respond.")
		 requesting = false
   end
end
cant_delete_account #4
Posted 17 September 2012 - 04:32 AM
Fixed page on the wiki.