Quantcast
Channel: SCN: Message List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 9165

Re: How to set CSRF token to make a POST call via Destinations in HANA XS

$
0
0

Hi Swetha,

the above example is exactly doing this!

 

You can get a CSRF via

 

function getCSRFToken(dest, client){

    var req = new $.web.WebRequest(

        $.net.http.HEAD,

        "/sap/opu/odata/iwfnd/catalogservice"

    );

    req.headers.set("x-csrf-token", "fetch");

    client.request(req, dest);

    var response = client.getResponse();

    var CSRF = response.headers.get("x-csrf-token");

    if (response.status===200) {}

    else {

        //handleErrors(response);

    }

    return CSRF;

}

 

 

a HEAD call will be enough (less footprint than GET because you only need the token).

 

Then you can call the needed OData service (or in my case directly the RFC)

 

    var req = new $.web.WebRequest(

        $.net.http.POST,

        "/sap/gw/jsonrpc"

    );

    req.contentType = "application/json";

    req.headers.set("x-csrf-token", CSRF);

// put your ODATA payload here instead RFC

    var requestData = {

        "jsonrpc": "2.0",

        "method": sMethod,

        "params": oParameters,

        "id": 1

    };

 

Regards,

Holger


Viewing all articles
Browse latest Browse all 9165

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>