sendRequest( method, url, header, requestBody, successCB, errorCB, [user], [password], [timeout], [certSource] ) method

Send an HTTP(S) request to a remote server.

This function is the centerpiece of the AuthProxy plugin. It will handle mutual authentication if a certificate source is provided. The success callback is invoked upon any response from the server. Even responses not generally considered to be successful (such as 404 or 500 status codes) will result in the success callback being invoked. The error callback is reserved for problems that prevent the AuthProxy from creating the request or contacting the server. It is therefore important to always check the status property on the object given to the success callback.

Syntax

sendRequest( method, url, header, requestBody, successCB, errorCB, [user], [password], [timeout], [certSource] ) → {function}

Parameters

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 send to the server.This is an Object. Can be null.
requestBody string   Data to send to the server with the request.Can be null.
successCB sap.AuthProxy~successCallback   Callback method invoked upon a response from the server.
errorCB sap.AuthProxy~errorCallback   Callback method invoked in case of failure.
user string (optional) User ID for basic authentication.
password string (optional) User password for basic authentication.
timeout number (optional) Timeout setting in seconds.Default timeout is 60 seconds. A value of 0 means there is no timeout.
certSource Object (optional) Certificate description object.It can be one of sap.AuthProxy#CertificateFromFile, sap.AuthProxy#CertificateFromStore, or sap.AuthProxy#CertificateFromLogonManager.

Returns

A JavaScript function object to abort the operation. Calling the abort function results in neither the success or error callback being invoked for the original request (excepting the case where the success or error callback was invoked before calling the abort function). Note that the request itself cannot be unsent, and the server will still receive the request - the JavaScript will just not know the results of that request.

Type:

function

Example

// callbacks
var successCB = function(serverResponse){
    alert("Status: " + JSON.stringify(serverResponse.status));
    alert("Headers: " + JSON.stringify(serverResponse.headers));
    alert("Response: " + JSON.stringify(serverResponse.response));
}
var errorCB = function(errorObject){
    alert("Error making request: " + JSON.stringify(errorObject));
}
// To send a post request to the server, call the method
var abortFunction = sap.AuthProxy.sendRequest("POST", "http://www.google.com", null, "THIS IS THE BODY", successCB, errorCB);
// An example of aborting the request
abortFunction();

// To send a post request to the server with headers, call the method
sap.AuthProxy.sendRequest("POST", url, {HeaderName : "Header value"}, "THIS IS THE BODY", successCB, errorCB);

// To send a post request to the server with basic authentication, call the method
sap.AuthProxy.sendRequest("POST", url, headers, "THIS IS THE BODY", successCB, errorCB, "username", "password");

// To send a post request to the server with mutual authentication, call the method
sap.AuthProxy.sendRequest("POST", "https://hostname", headers, "THIS IS THE BODY", successCB, errorCB, null, 
    null, 0, new sap.AuthProxy.CertificateFromLogonManager("theAppId"));

Source

authproxy.js, line 467.