Constructor
new Http()
Create a new Http instance. By default, a PlayCanvas application creates an instance of this
object at `pc.http`.
- Source:
Methods
del(url, optionsopt, callback) → {XMLHttpRequest}
Perform an HTTP DELETE request to the given url
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
url |
Object | The URL to make the request to | |||||||||||||||||||||||||||||||||||||||||
options |
Object |
<optional> |
Additional options
Properties
|
||||||||||||||||||||||||||||||||||||||||
callback |
function | The callback used when the response has returned. Passed (err, data) where data is the response (format depends on response type: text, Object, ArrayBuffer, XML) and err is the error code. |
- Source:
Returns:
The request object.
- Type
- XMLHttpRequest
get(url, optionsopt, callback) → {XMLHttpRequest}
Perform an HTTP GET request to the given url.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
url |
String | The URL to make the request to. | |||||||||||||||||||||||||||||||||||||||||
options |
Object |
<optional> |
Additional options
Properties
|
||||||||||||||||||||||||||||||||||||||||
callback |
function | The callback used when the response has returned. Passed (err, data) where data is the response (format depends on response type: text, Object, ArrayBuffer, XML) and err is the error code. |
- Source:
Returns:
The request object.
- Type
- XMLHttpRequest
Example
pc.http.get("http://example.com/", function (err, response) {
console.log(response);
});
post(url, data, optionsopt, callback) → {XMLHttpRequest}
Perform an HTTP POST request to the given url.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
url |
String | The URL to make the request to. | |||||||||||||||||||||||||||||||||||||
data |
Object | Data to send in the body of the request. Some content types are handled automatically. If postdata is an XML Document, it is handled. If the Content-Type header is set to 'application/json' then the postdata is JSON stringified. Otherwise, by default, the data is sent as form-urlencoded. | |||||||||||||||||||||||||||||||||||||
options |
Object |
<optional> |
Additional options
Properties
|
||||||||||||||||||||||||||||||||||||
callback |
function | The callback used when the response has returned. Passed (err, data) where data is the response (format depends on response type: text, Object, ArrayBuffer, XML) and err is the error code. |
- Source:
Returns:
The request object.
- Type
- XMLHttpRequest
put(url, data, optionsopt, callback) → {XMLHttpRequest}
Perform an HTTP PUT request to the given url.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
url |
String | The URL to make the request to. | |||||||||||||||||||||||||||||||||||||
data |
Document | Object | Data to send in the body of the request. Some content types are handled automatically. If postdata is an XML Document, it is handled. If the Content-Type header is set to 'application/json' then the postdata is JSON stringified. Otherwise, by default, the data is sent as form-urlencoded. | |||||||||||||||||||||||||||||||||||||
options |
Object |
<optional> |
Additional options
Properties
|
||||||||||||||||||||||||||||||||||||
callback |
function | The callback used when the response has returned. Passed (err, data) where data is the response (format depends on response type: text, Object, ArrayBuffer, XML) and err is the error code. |
- Source:
Returns:
The request object.
- Type
- XMLHttpRequest
request(method, url, optionsopt, callback) → {XMLHttpRequest}
Make a general purpose HTTP request.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
method |
String | The HTTP method "GET", "POST", "PUT", "DELETE" | |||||||||||||||||||||||||||||||||||||||||
url |
String | The url to make the request to | |||||||||||||||||||||||||||||||||||||||||
options |
Object |
<optional> |
Additional options
Properties
|
||||||||||||||||||||||||||||||||||||||||
callback |
function | The callback used when the response has returned. Passed (err, data) where data is the response (format depends on response type: text, Object, ArrayBuffer, XML) and err is the error code. |
- Source:
Returns:
The request object.
- Type
- XMLHttpRequest