cancel
Showing results for 
Search instead for 
Did you mean: 

URL parameters or request Body- XSJS

former_member206787
Participant
0 Kudos

Hi,

Should we use url parameters to send data to service for a POST call or send the data as body in the request?

What is the right way to do in terms of standards and security?

Regards,

Pranjal

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Pranjal,

Sending parameters via url would be a huge task especially when you have a huge amount of data. Sending the data as body and then consuming it in XSJS would be the right way of doing this.(i guess!)

Regards,

Pratik

former_member206787
Participant
0 Kudos

Hi Pratik,

Is it ok to send data in body of a GET call?

Regards,

Pranjal

Former Member
0 Kudos

GET will read the data. you can use POST for sending it. see the below snippet:

var token = XMLHttpRequest.getResponseHeader('X-CSRF-Token');

  $.ajax({

  url: <target_url>,

  type: "POST",

  beforeSend: function(xhr) 

                    {     

                              xhr.setRequestHeader("X-CSRF-Token", token); 

                    }, 

  processData :false,

  contentType: false,

  POST_DATA:data,

  success:function(){

  alert("sucess in post");

  },

  error:function(){

  alert("fail");

  }

  })


here, "data" would be anything that you have read, maybe a JSON being read from a GET.


so, initially you would read the data from a source URL and get it in say JSON format and then using POST, you can send it to the target URL.


Additionally, take a look at


Hope this helps!