Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Node.js code for HTTP POST with X-CSRF-Token

Hi all,

I am currently experimenting with a IoT solution. Instead of using the HCP, with the preconfigured IoT services, I have created an oData service on a HANA system on AWS.

To test the HTTP GET and the HTTP POST, I have used Postman, and it works. The HTTP POST via postman can be achieved by providing the X-CSRF-Token in the header data, which I have fetched first using a HTTP GET.

Now I am trying to replicate this with a Node.js javascript. However, after I have fetched the X-CSRF-Token with a HTTP GET, I want to do a HTTP POST with the actual data, and also with the X-CSRF-Token filled with the value i got from the fetch. However, the token value is not valid anymore when I create the POST request. I have tried to keep the session open, by using a http agent (keepAlive : true, maxSockets : 1), but with no success.

I also tried to turn off the X-CSRF-Token by changing the GUI parameters of my oData service in SICF by putting parameter ~CHECK_CSRF_TOKEN to 0, but also without success.

Does anyone know how this could be done with node.js?

Many thanks,

Steven Spronk

Former Member
Not what you were looking for? View more on this topic or Ask a question