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

HTTP api

Started by niels22, 30 January 2013 - 02:10 AM
niels22 #1
Posted 30 January 2013 - 03:10 AM
Hello there

I'm playing on a server, with http api enabled, and it doesn't seem to get the text


bin = "hrey35f"		   (<-- sample)
txt = http.request("http://pastebin.com/" ..bin)
local event, url, sourceText = os.pullEvent("http_success")
su = fs.open("startup","w")
su.write(txt)

I've used that for a long time, but it doesn'r write anything to "startup"

Why is this?
theoriginalbit #2
Posted 30 January 2013 - 03:12 AM
why don't you just use the pastebin program thats made for you?

also just a side note you're not getting the raw version of the paste, just the html formatted one.
remiX #3
Posted 30 January 2013 - 03:23 AM
Yeah, as TOB said - you need to request from the raw website of the code from pastebin:
local response = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode( bin ))

What the textutils.urlEncode does is encode the url, like change spaces into % signs etc, can't remember exactly what it does, but in this case - you probably wouldn't need it.

Just open the website on your browser with the raw website and you can see the difference.
theoriginalbit #4
Posted 30 January 2013 - 03:26 AM
What the textutils.urlEncode does is encode the url, like change spaces into % signs etc, can't remember exactly what it does, but in this case - you probably wouldn't need it.
Yeh defs not needed for pastebin urls. but it basically turns all non-alphanumeric character into its percent escaped equivalent.