#hs.http
Perform HTTP requests
#API Overview
Variables - Configurable values
Functions - API calls offered directly by the extension
- asyncGet
- asyncPost
- asyncPut
- convertHtmlEntities
- doAsyncRequest
- doRequest
- encodeForQuery
- get
- post
- put
- registerEntity
- urlParts
#API Documentation
#Variables
#Functions
| | | | --------------------------------------------|-------------------------------------------------------------------------------------| | Signature | hs.http.asyncGet(url, headers, callback)
| | Type | Function | | Description | Sends an HTTP GET request asynchronously | | Parameters |
- url - A string containing the URL to retrieve
- headers - A table containing string keys and values representing the request headers, or nil to add no headers
- callback - A function to be called when the request succeeds or fails. The function will be passed three parameters: A number containing the HTTP response status A string containing the response body A table containing the response headers
- None
- If authentication is required in order to download the request, the required credentials must be specified as part of the URL (e.g. "http://user:password@host.com/"). If authentication fails, or credentials are missing, the connection will attempt to continue without credentials.
- If the request fails, the callback function's first parameter will be negative and the second parameter will contain an error message. The third parameter will be nil
| | | | --------------------------------------------|-------------------------------------------------------------------------------------| | Signature | hs.http.asyncPost(url, data, headers, callback)
| | Type | Function | | Description | Sends an HTTP POST request asynchronously | | Parameters |
- url - A string containing the URL to submit to
- data - A string containing the request body, or nil to send no body
- headers - A table containing string keys and values representing the request headers, or nil to add no headers
- callback - A function to be called when the request succeeds or fails. The function will be passed three parameters: A number containing the HTTP response status A string containing the response body A table containing the response headers
- None
- If authentication is required in order to download the request, the required credentials must be specified as part of the URL (e.g. "http://user:password@host.com/"). If authentication fails, or credentials are missing, the connection will attempt to continue without credentials.
- If the request fails, the callback function's first parameter will be negative and the second parameter will contain an error message. The third parameter will be nil
| | | | --------------------------------------------|-------------------------------------------------------------------------------------| | Signature | hs.http.asyncPut(url, data, headers, callback)
| | Type | Function | | Description | Sends an HTTP PUT request asynchronously | | Parameters |
- url - A string containing the URL to submit to
- data - A string containing the request body, or nil to send no body
- headers - A table containing string keys and values representing the request headers, or nil to add no headers
- callback - A function to be called when the request succeeds or fails. The function will be passed three parameters: A number containing the HTTP response status A string containing the response body A table containing the response headers
- None
- If authentication is required in order to download the request, the required credentials must be specified as part of the URL (e.g. "http://user:password@host.com/"). If authentication fails, or credentials are missing, the connection will attempt to continue without credentials.
- If the request fails, the callback function's first parameter will be negative and the second parameter will contain an error message. The third parameter will be nil
| | | | --------------------------------------------|-------------------------------------------------------------------------------------| | Signature | hs.http.doAsyncRequest(url, method, data, headers, callback, [cachePolicy|enableRedirect])
| | Type | Function | | Description | Creates an HTTP request and executes it asynchronously | | Parameters |
- url - A string containing the URL
- method - A string containing the HTTP method to use (e.g. "GET", "POST", etc)
- data - A string containing the request body, or nil to send no body
- headers - A table containing string keys and values representing request header keys and values, or nil to add no headers
- callback - A function to called when the response is received. The function should accept three arguments: code - A number containing the HTTP response code body - A string containing the body of the response headers - A table containing the HTTP headers of the response
- cachePolicy - An optional string containing the cache policy ("protocolCachePolicy", "ignoreLocalCache", "ignoreLocalAndRemoteCache", "returnCacheOrLoad", "returnCacheDontLoad" or "reloadRevalidatingCache"). Defaults to
protocolCachePolicy
. - enableRedirect - An optional boolean to indicate whether to redirect the http request. Defaults to true.
- None
- If authentication is required in order to download the request, the required credentials must be specified as part of the URL (e.g. "http://user:password@host.com/"). If authentication fails, or credentials are missing, the connection will attempt to continue without credentials.
- If the Content-Type response header begins
text/
then the response body return value is a UTF8 string. Any other content type passes the response body, unaltered, as a stream of bytes. - If enableRedirect is set to true, response body will be empty string. Http body will be dropped even though response has the body. This seems the limitation of 'connection:willSendRequest:redirectResponse' method.