sending ajax get request with content type :application/xml is still giving me json response

Viewed 120

I've been constructing this ajax request

<script>
  $.ajax({
      url:"https://api.asd.com/v1/book?limit_bids=450&limit=20",
        type:"GET",

      data:{


  },
      contentType:"application/xml",
      success: function (response) {
           console.log(headers),
          console.log(response)

      }

  });
  </script>

i was expecting it to return a xml based response or text/html based 400 bad request [which it should]

but instead i got JSON response

but triggering the same request in burp or postman is giving me the response which i wanted

enter image description here

the thing is content-lenfth is required to get that exact response

but having content-length header is not being accepted in ajax request so im assuming content-length will autoamtically be added by ajax while sending the data in requet

      data:{
"asd"

  },

is giving me error

      data:{
"asd":"asd"

  }

is still giving me a json response

so how exactly i need to construct the request?

so that i can get the response i wanted from that image not just ajax but any other methods like

jquery or XMLHttpRequest
1 Answers

Ajax GET requests do not have body content so they would not have content lengths or content types.
If you want to tell the api that you want an xml response you have to set the dataType field in $.ajax. This of course has to be supported by the API, just saying you want xml doesn't guarantee you will get it.

$.ajax({
  url:"https://api.asd.com/v1/book?limit_bids=450&limit=20",
  type:"GET",
  dataType:"xml",
  success: function (response) {
    console.log(response);
  }
});
Related