Send a HTTP(S) GET request to a remote server.
<static> get( url, header, requestBody, successCB, [errorCB], [user], [password], [timeout], [certSource] ) → {anonymous.abort}
| Name | Type | Argument | Description |
| 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 | (optional) | 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. |
A JavaScript function object to cancel the operation.
[/reference/refbody/section/sectiondiv {""})Type:
(sectiondiv]// To send a get request to server, call the method
HttpsConnection.get("http://www.google.com", null, function (data) {
alert("Status: " + JSON.stringify(data.status));
alert("Headers: " + JSON.stringify(data.headers));
if (data.responseText){
alert("Response: " + JSON.stringify(data.responseText));
}
},
function (error) {
alert("Failed: " + JSON.stringify(error));
}};
// To send a get request to server with headers, call the method
HttpsConnection.get(url, {HeaderName : "Header value"}, successCB, errorCB);
// To send a get request to server with basic authentication, call the method
HttpsConnection.get(url, headers, successCB, errorCB, "username", "password");
// To send a get request to server with mutual authentication, call the method
HttpsConnection.get("https://hostname", headers, successCB, errorCB, null, null, 0,
new CertificateFromFile("/mnt/sdcard/my.p12", "password", "mykey"));