Garry's Mod Wiki

Revision Difference

http.Post#511594

<function name="Post" parent="http" type="libraryfunc">⤶ <description>⤶ Sends an asynchronous POST request to a HTTP server.⤶ ⤶ HTTP requests returning a status code &amp;gt;= 400 are still considered a success and will call the onSuccess callback.⤶ ⤶ The onFailure callback is usually only called on DNS or TCP errors (e.g. the website is unavailable or the domain does not exist)⤶ </description>⤶ <realm>Shared and Menu</realm>⤶ <file line="46-L73">lua/includes/modules/http.lua</file>⤶ <args>⤶ <arg name="url" type="string">The url to of the website to fetch.</arg>⤶ <arg name="parameters" type="table">The post parameters to be send to the server. `&#x27;Keys and values `must&#x27;&#x27; be strings.</arg>⤶ <arg name="onSuccess" type="function" default="nil">The function called on success: function( string responseText, number contentLength, table responseHeaders, number statusCode )</arg>⤶ <arg name="onFailure" type="function" default="nil">The function called on failure: function( string errorMessage )</arg>⤶ <arg name="headers" type="table" default="{}">KeyValue table for headers</arg>⤶ </args>⤶ </function>⤶ ⤶ <example>⤶ <description>⤶ Write a file in PHP, and invoke it from Lua. The output below is written in the file, not in the console.⤶ ⤶ &amp;lt;pre class="plain"&amp;gt;&amp;lt;?php⤶ $p = $_POST["p"];⤶ $a = $_POST["a"];⤶ ⤶ $f = fopen("write.html", "w");⤶ ⤶ fwrite($f, "This is a test. $p $a\n");⤶ ⤶ fclose($f);⤶ ?&amp;gt;&amp;lt;/pre&amp;gt;⤶ </description>⤶ <code>⤶ http.Post("http://localhost/post.php", { p = "Gmod", a = "Test" }, function(result)⤶ if result then print("Done!") end⤶ end, function(failed)⤶ print(failed)⤶ end)⤶ </code>⤶ <outputfixedwidth>Fixed width</outputfixedwidth>⤶ <output>This is a test. Gmod Test</output>⤶ ⤶ </example>