PostAsync
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts.
For thread safety, this property is not safe to read in an unsynchronized thread.
The PostAsync function sends an HTTP POST request. It functions similarly to HttpService/RequestAsync|RequestAsync except that it accepts HTTP request parameters as method parameters instead of a single dictionary and returns only the body of the HTTP response. Generally, this method is useful only as a shorthand and HttpService/RequestAsync|RequestAsync should to be used in most cases. For a detailed guide on sending and retrieving data via HTTP requests, see the Sending HTTP Requests article.
When true, the compress parameter controls whether large request bodies will be compressed using gzip.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
|
|
The destination address for the data |
||
|
|
The data being sent |
||
|
ApplicationJson
|
Modifies the value in the Content-Type header sent with the request |
||
|
false
|
Determines whether the data is compressed (gzipped) when sent |
||
|
|
Used to specify some HTTP request headers |
Returns
| Return Type | Summary |
|---|---|
|
The HTTP response sent back indicating the request result |
Code Samples
New Pastebin Post
Pastebin.com is a website that allows users to paste text (usually source code) for others to view publicly. This code sample uses HttpService PostAsync and the pastebin web API to automatically create a new public paste on the website. Since pastebin’s API is designed to take data in as a URL encoded string, the code uses a for-loop to turn the dataFields table into a URL encoded string, such as hello=world&foo=bar. This is used as the HTTP POST data.
Test this code by first going to pastebin.com/api#1 and getting an API key (you’ll need a pastebin account to do this). Then, paste your unique developer API key into the field api_dev_key in the code sample’s dataFields table. Fill in any other information about the post you want to make, then run this code in a Script (not a LocalScript). If all goes well, you’ll get a URL to your new paste in the Output window (or some error string from pastebin).