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

CSRF token validation failed in Odata4j

$
0
0

Hi all,

 

I'm trying to post the entry to Odata service Url which is created in ABAP backend. When i'm trying to send the data from java code to ABAP system via Odata service, I'm getting CSRF Token validation error. Below is the code snippet for Odata Post service

 

 

// TESTCASEXML_ODATA = URL of the Odata service

ODataJerseyConsumer consumer = ODataJerseyConsumer.create(TESTCASEXML_ODATA);

  ODataJerseyConsumer.Builder builder = ODataJerseyConsumer.newBuilder(TESTCASEXML_ODATA);

              

                 // Authentication

                 builder.setClientBehaviors(new OClientBehavior(){          

                          @Override

                          public ODataClientRequest transform(ODataClientRequest request) {

                             String userPassword = USERNAME + ":" + PASSWORD;

                             String encoded = Base64.encodeBase64String(userPassword.getBytes());

                             encoded = encoded.replaceAll("\r\n?", "");

                                   

                              // Necessary headers to do PUT and POST operations

                             request = request.header("X-Requested-With", "XMLHttpRequest")

                                              .header("Authorization", "Basic " + encoded);     

                                           

                             return request;

                       }});

                 consumer = builder.build();

              

            

 

 

  OCreateRequest<OEntity> createRequest = consumer.createEntity("LogSet").properties(OProperties.string("TestplanId", "111")).properties(OProperties.string("ProcessId", "222")).properties(OProperties.string("Seqno", "33"));

       

 

 

  // Execute the OData post

  createRequest.execute();

 

 

 

 

 

Please suggest me the solution to avoid this issue

 

Thanks and Regards,

Naveen


Viewing all articles
Browse latest Browse all 2823

Trending Articles



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