Developer

Adding Cookies to a Request

To add cookies to a request for authentication, use the header object that is passed to the get/sendRequest functions.  

Only the cookie name and value should be set this way.  The other pieces of the cookie (domain, path, and so on) are set automatically based on the URL the request is made against.  The cookie is treated as a session cookie and sent on future requests as appropriate.  The API examples below show an example of how to set a cookie with the header object.

var successCallback = function( result ){
     if( result.status === 200 ) {
          alert("success\!
        Response text: " + result.responseText );
     } else {
          alert("Not success, response status:
        " + result.status);
     }
}

var failureCallback = function( error ) {
     alert("Error! Code: " + error.errorCode + "\n" + error.description + "\nNative error code: " + error.nativeErrorCode );
}

// setting a cookie with a request
var header = {cookie: "customCookieName=customCookieValue;anotherName=AnotherValue"};

sap.AuthProxy.sendRequest("POST", "http://www.example.com/stuff/etc", header, null, successCallback, failureCallback);