Quantcast
Channel: SCN : All Content - SAP Gateway
Viewing all articles
Browse latest Browse all 2823

Adding Header to Odata Post Request

$
0
0

Hi

 

We are trying to post data to a webservice url using odata4j and we are following CSRF token validation failed error.  The code we are currently using is


               ODataConsumer.Builder builder = ODataConsumers.newBuilder(url to which post is to be done);

               builder.setClientBehaviors(new BasicAuthenticationBehavior(username,password));

               ODataConsumer c = builder.build();

               OEntity newProduct = c.createEntity(EntityName)

 

                       .properties(OProperties.string("ID", "57"))

                       .execute();

                ODataConsumer.dump.all(true);



 

I guess the problem here is the header to which I should add the CSRF token and I am looking for a way to add headers to ODataConsumer. I have also tried ODataClientRequest with which I am able to add headers but adding Entity is causing problems. The code is



 

                 ODataClientRequest clientRequest = new ODataClientRequest("POST", serviceUrl, headers, null, null);

 

                 clientRequest.header("X-CSRF-Token", "OcjGKcE-kYF3MmNvaklKqg==");

                 BasicAuthenticationBehavior bs = new BasicAuthenticationBehavior(username,password);


Here we are not able to create entity which is to be posted to the webservice url.

Please provide a solution.

Thanks and Regards

Jaidish hari raj P M


Viewing all articles
Browse latest Browse all 2823

Trending Articles



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