Send a HTTP(S) request to a remote server.
<static> sendRequest( method, url, header, requestBody, successCB, errorCB, [user], [password], [timeout], [certSource] ) → {anonymous.abort}
| Name | Type | Argument | Description |
| method | string | Standard HTTP request method name. | |
| url | string | The http url with format http(s)://[user:password]@hostname[:port]/path. | |
| header | Object | HTTP header to be sent to server.This is an Object. Can be null. | |
| requestBody | string | Data to be sent to server with the request.It’s a string value. Can be null. | |
| successCB | anonymous.sendRequestSuccessCB | Callback method upon success. | |
| errorCB | anonymous.sendRequestErrorCB | Callback method upon failure. | |
| user | string | (optional) | User ID for basic authentication. |
| password | string | (optional) | User password for basic authentication. |
| timeout | number | (optional) | Timeout setting in seconds. |
| certSource | Object | (optional) | Certificate description object.It can be one of HttpsConnection.CertificateFromFile, HttpsConnection.CertificateFromStore, or HttpsConnection.CertificateFromAfaria. |
// To send a post request to server, call the method
HttpsConnection.sendRequest("POST", "http://www.google.com", null, "THIS IS THE BODY", function (data) {
alert("Status: " + JSON.stringify(data.status));
alert("Headers: " + JSON.stringify(data.headers));
alert("Response: " + JSON.stringify(data.response));
}, function (data) {
alert("Failed: " + JSON.stringify(data));}};
// To send a post request to server with headers, call the method
HttpsConnection.sendRequest("POST", url, {HeaderName : "Header value"}, "THIS IS THE BODY", successCB, errorCB);
// To send a post request to server with basic authentication, call the method
HttpsConnection.sendRequest("POST", url, headers, "THIS IS THE BODY", successCB, errorCB, "username", "password");
// To send a post request to server with mutual authentication, call the method
HttpsConnection.sendRequest("POST", "https://hostname", headers, "THIS IS THE BODY", successCB, errorCB, null,
null, 0, new CertificateFromFile("/mnt/sdcard/my.keystore", "password", "mykey"));