<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://www.computercraft.info/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=AgentE382</id>
		<title>ComputerCraft Wiki - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://www.computercraft.info/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=AgentE382"/>
		<link rel="alternate" type="text/html" href="https://www.computercraft.info/wiki/Special:Contributions/AgentE382"/>
		<updated>2026-07-11T07:53:07Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.24.1</generator>

	<entry>
		<id>https://www.computercraft.info/wiki/index.php?title=HTTP_(API)&amp;diff=6575</id>
		<title>HTTP (API)</title>
		<link rel="alternate" type="text/html" href="https://www.computercraft.info/wiki/index.php?title=HTTP_(API)&amp;diff=6575"/>
				<updated>2014-06-05T21:46:27Z</updated>
		
		<summary type="html">&lt;p&gt;AgentE382: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;:{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| '''The HTTP API must be enabled in ComputerCraft.cfg before being used. To enable it see [http://www.computercraft.info/forums2/index.php?/topic/17533-how-to-enable-the-http-api/ this tutorial].'''&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The HTTP API allows interfacing with websites and downloading from them.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table style=&amp;quot;width: 100%; border: solid 1px black; margin: 2px; border-spacing: 0px;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td colspan=&amp;quot;3&amp;quot; style=&amp;quot;font-weight: bold; font-size: large; padding-bottom: .3em; border-bottom: solid #C9C9C9 1px; background: #D3FFC2; line-height:28px;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:Grid_disk.png|24px]]&amp;amp;nbsp;&amp;amp;nbsp;&lt;br /&gt;
HTTP (API)&lt;br /&gt;
&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td style=&amp;quot;width: 100px; background: #E0E0E0; padding: .4em; font-weight:bold;&amp;quot;&amp;gt;Return&amp;lt;/td&amp;gt;&amp;lt;td style=&amp;quot;width: 350px; background: #E0E0E0; padding: .4em; font-weight:bold;&amp;quot;&amp;gt;Method Name&amp;lt;/td&amp;gt;&amp;lt;td style=&amp;quot;background: #E0E0E0; padding: .4em; font-weight:bold;&amp;quot;&amp;gt;Description&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr style=&amp;quot;background-color: #FFFFFF;&amp;quot;&amp;gt;&amp;lt;td style=&amp;quot;border-top: solid #C9C9C9 1px; padding: .4em;&amp;quot;&amp;gt;[[nil]]&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td style=&amp;quot;border-top: solid #C9C9C9 1px; padding: .4em;&amp;quot;&amp;gt;[[http.request]]({{type|string}} url [, {{type|string}} postData [, {{type|table}} headers]])&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td style=&amp;quot;border-top: solid #C9C9C9 1px; padding: .4em;&amp;quot;&amp;gt;Sends a HTTP request to a website, asynchronously.&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr style=&amp;quot;background-color: #E8E8E8;&amp;quot;&amp;gt;&amp;lt;td style=&amp;quot;border-top: solid #C9C9C9 1px; padding: .4em;&amp;quot;&amp;gt;{{type|table}} handle&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td style=&amp;quot;border-top: solid #C9C9C9 1px; padding: .4em;&amp;quot;&amp;gt;[[http.get]]({{type|string}} url [, {{type|table}} headers])&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td style=&amp;quot;border-top: solid #C9C9C9 1px; padding: .4em;&amp;quot;&amp;gt;Sends a HTTP GET request to a website, synchronously.&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr style=&amp;quot;background-color: #FFFFFF;&amp;quot;&amp;gt;&amp;lt;td style=&amp;quot;border-top: solid #C9C9C9 1px; padding: .4em;&amp;quot;&amp;gt;{{type|table}} handle&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td style=&amp;quot;border-top: solid #C9C9C9 1px; padding: .4em;&amp;quot;&amp;gt;[[http.post]]({{type|string}} url, {{type|string}} postData [, {{type|table}} headers])&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td style=&amp;quot;border-top: solid #C9C9C9 1px; padding: .4em;&amp;quot;&amp;gt;Sends a HTTP POST request to a website, synchronously.&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[http.request]] is used to send a HTTP request that completes asynchronously and generates an event (one of [[Http success (event)|http_success]] or [[Http failure (event)|http_failure]]). [[http.get]] and [[http.post]] execute [[http.request]] and block until the operation completes.&lt;br /&gt;
&lt;br /&gt;
== Handles ==&lt;br /&gt;
All three operations make use of ''handles'', tables that contain functions to read data returned from the HTTP server. These handles act the same as the I/O handles returned by [[fs.open]] in read-only text mode, implementing the [[fs.open#Closing_a_file_handle|close]], [[fs.open#Files_opened_in_text_read_mode|readLine]], and [[fs.open#Files_opened_in_text_read_mode|readAll]] methods. These handles also implement the following function:&lt;br /&gt;
&lt;br /&gt;
{{Function&lt;br /&gt;
|name=&amp;lt;var&amp;gt;h&amp;lt;/var&amp;gt;.getResponseCode&lt;br /&gt;
|returns={{type|number}} HTTP response code&lt;br /&gt;
|api=HTTP&lt;br /&gt;
|desc=Returns the numerical [https://en.wikipedia.org/wiki/List_of_HTTP_status_codes HTTP response code] sent by the server&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Headers ==&lt;br /&gt;
As of '''ComputerCraft 1.63''', you can optionally set custom headers. This also means that you can override default headers such as the User-Agent.&lt;br /&gt;
{{Example&lt;br /&gt;
|desc=Sends a request to http://example.com/ with the custom headers.&lt;br /&gt;
|code=&amp;lt;nowiki&amp;gt;local headers = {&lt;br /&gt;
  [&amp;quot;User-Agent&amp;quot;] = &amp;quot;A custom user-agent!&amp;quot;, -- Overrides the default User-Agent.&lt;br /&gt;
  [&amp;quot;Hi&amp;quot;] = &amp;quot;Hello&amp;quot; -- A non-standard custom header field.&lt;br /&gt;
}&lt;br /&gt;
http.get(&amp;quot;http://example.com/&amp;quot;, headers)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
=== Caution ===&lt;br /&gt;
You '''must''' either pass a ''string'' or ''nil'' as the second argument of http.request(). It will silently fail if you try to pass a header table as the second argument.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http.request(&amp;quot;http://example.com/&amp;quot;, headers) -- This will produce a normal GET request.&lt;br /&gt;
http.request(&amp;quot;http://example.com/&amp;quot;, nil, headers) -- This will produce a GET request with your custom headers.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:APIs]]&lt;/div&gt;</summary>
		<author><name>AgentE382</name></author>	</entry>

	<entry>
		<id>https://www.computercraft.info/wiki/index.php?title=Thread_(type)&amp;diff=6147</id>
		<title>Thread (type)</title>
		<link rel="alternate" type="text/html" href="https://www.computercraft.info/wiki/index.php?title=Thread_(type)&amp;diff=6147"/>
				<updated>2014-03-25T02:33:33Z</updated>
		
		<summary type="html">&lt;p&gt;AgentE382: Added to &amp;quot;type&amp;quot; category.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Coroutine_(type)]]&lt;br /&gt;
[[Category:Lua Types]]&lt;/div&gt;</summary>
		<author><name>AgentE382</name></author>	</entry>

	<entry>
		<id>https://www.computercraft.info/wiki/index.php?title=Thread_(type)&amp;diff=6146</id>
		<title>Thread (type)</title>
		<link rel="alternate" type="text/html" href="https://www.computercraft.info/wiki/index.php?title=Thread_(type)&amp;diff=6146"/>
				<updated>2014-03-25T02:32:43Z</updated>
		
		<summary type="html">&lt;p&gt;AgentE382: Added redirect for completeness.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Coroutine_(type)]]&lt;/div&gt;</summary>
		<author><name>AgentE382</name></author>	</entry>

	<entry>
		<id>https://www.computercraft.info/wiki/index.php?title=Function_(type)&amp;diff=6145</id>
		<title>Function (type)</title>
		<link rel="alternate" type="text/html" href="https://www.computercraft.info/wiki/index.php?title=Function_(type)&amp;diff=6145"/>
				<updated>2014-03-25T02:29:15Z</updated>
		
		<summary type="html">&lt;p&gt;AgentE382: Added to &amp;quot;type&amp;quot; category.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Tutorials]]&lt;br /&gt;
{{Tutorial&lt;br /&gt;
|name=Functions&lt;br /&gt;
|desc=An introduction to functions.&lt;br /&gt;
|objective=To gain an understanding of how Functions work, and how to use them&lt;br /&gt;
|prereqs=[[Variables|A basic understanding of Variables]].&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== What are functions? ==&lt;br /&gt;
&lt;br /&gt;
Functions are a useful tool that helps simplify code, separating it by functionality and reducing repetitiveness. Understanding functions is key to becoming a successful coder. When a function is defined in Lua, it will most likely look like this:&lt;br /&gt;
 function FunctionName()&lt;br /&gt;
   --Do stuff&lt;br /&gt;
 end&lt;br /&gt;
But may occasionally look more like a regular variable&lt;br /&gt;
 Functionname=function()&lt;br /&gt;
   --Do stuff&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Both methods will yield the same result, so it's generally down to personal preference. Since functions are treated as normal variables, it is also possible to copy a function to a new variable&lt;br /&gt;
 NewFunctionname=OldFunctionName&lt;br /&gt;
Note that here, we aren't using the &amp;quot;()&amp;quot; present in the other methods. This is because we're using OldFunctionName as a variable, and not calling it as a function.&lt;br /&gt;
&lt;br /&gt;
== How do I use functions? ==&lt;br /&gt;
&lt;br /&gt;
More than likely, if you've followed the &amp;quot;Hello World&amp;quot; tutorial, you have already used functions. Without standard in-built functions such as write() and print(), it would be impossible to interact with a user. Whenever you see brackets after a variable name, you know it's a function.&lt;br /&gt;
&lt;br /&gt;
For our first example, we will write a simple function that will use write()&lt;br /&gt;
 function MyFunction(Str)&lt;br /&gt;
   write(Str)&lt;br /&gt;
 end&lt;br /&gt;
 MyFunction(&amp;quot;I am writing text to the screen!\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
If you have successfully written and executed this script, it should write &amp;quot;I am writing text to the screen!&amp;quot; on the screen. Notice how the function has a variable name in the brackets. This is called an &amp;quot;'''argument'''&amp;quot;, and will likely be crucial to your functions later. There can be any number of arguments, separated by commas, and arguments can be any type of variable, including other functions. It is also very important to call your function after you have defined it otherwise you will get an error like &amp;quot;attempt to call nil&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Add the following line to your code&lt;br /&gt;
 MyFunction( true )&lt;br /&gt;
This will pass a boolean value to your function, and it will error as it reaches the write(), which can't use a boolean value. To fix this, we'll need to validate what type of variable is being given. Try adding another line so your code looks like this:&lt;br /&gt;
 function MyFunction( Str )&lt;br /&gt;
   if type( Str ) ~= &amp;quot;string&amp;quot; then return end&lt;br /&gt;
   write( Str )&lt;br /&gt;
 end&lt;br /&gt;
 MyFunction( &amp;quot;I am writing text to the screen!\n&amp;quot; )&lt;br /&gt;
 MyFunction( true )&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;type&amp;quot; functions will give you a string with the type of variable you give it. In this case, if the variable is not a string, it will run &amp;quot;return&amp;quot;. Return will be described in more detail later in this tutorial, but for now we only need to know it ends the function, so any code after it will not be run. If you run your script now, you will see that there will be no error when it tries to use the boolean value. In fact, it will produce nothing at all, which may not be desirable. Edit the return line so it reads as follows&lt;br /&gt;
 if type( Str ) ~= &amp;quot;string&amp;quot; then print(&amp;quot;Bad argument #1 to MyFunction: String expected, got &amp;quot;.. type( Str )..&amp;quot;!\n&amp;quot;) return end&lt;br /&gt;
If you run the code again, you will find it now gives an error when it reaches the boolean. The difference between this and the usual error() command called for a real error, is that this won't exit your code, and any line afterwards will still run as normal.&lt;br /&gt;
&lt;br /&gt;
All this script really does is give a new name to the write() function, so there is a simpler way to do it. Before reading the following code, see if you can use your current knowledge to work it out for yourself.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The simplest way to get a new name for a function is as follows.&lt;br /&gt;
 MyFunction = write&lt;br /&gt;
This means that any call to MyFunction() will act as write() did. Note that any changes to write() ''after'' this line will not edit MyFunction, which is why this method is often used to back up a built-in function before it's overwritten. As an example, someone may want to disable the write() function, but still have a way to use it when necessary.&lt;br /&gt;
 MyFunction = write&lt;br /&gt;
 write = function() MyFunction(&amp;quot;This function has been disabled!\n&amp;quot;) end&lt;br /&gt;
This will write &amp;quot;This function has been disabled!&amp;quot; every time someone tries to use write()&lt;br /&gt;
&lt;br /&gt;
== Return ==&lt;br /&gt;
&lt;br /&gt;
Sometimes you will want a function to give a value back when it is done. This is the purpose of &amp;quot;return&amp;quot;, it will return one or more values and end the function.&lt;br /&gt;
 local function RandomNumber()&lt;br /&gt;
   local rand = math.random(0,10)&lt;br /&gt;
   return rand&lt;br /&gt;
 end&lt;br /&gt;
 local Num = RandomNumber()&lt;br /&gt;
&lt;br /&gt;
This will set Num to a random number between 0 and 10. Notice how this time we are including the () for the function, this means we're calling the function rather than using it as a variable.&lt;br /&gt;
&lt;br /&gt;
[[Category:Lua_Types]]&lt;/div&gt;</summary>
		<author><name>AgentE382</name></author>	</entry>

	</feed>