I need to simulate this curl command
curl -i -H "Accept: application/json" -H "Content-type:application/json" -X POST -d '{"username":"pippo","password":"secret123"}' http://url.org/api/login
via jquery, I made in this way
$( document ).ready(function() {
$.ajax({
url:"http://urlapi/user/login",
type:"POST",
headers: {
"Accept" : "application/json; charset=utf-8",
"Content-Type": "application/json; charset=utf-8"
},
data:{ username: "pippo", password: "secret123" },
dataType:"json"
})
});
I still have has content-type text/html. Is it right?
Try beforeSend in your jQuery AJAX call:
$( document ).ready(function() {
$.ajax({
url:"http://urlapi/user/login",
type:"POST",
beforeSend: function(xhr){
xhr.setRequestHeader("Content-Type","application/json");
xhr.setRequestHeader("Accept","application/json");
},
data:{ username: "pippo", password: "secret123" },
dataType:"json"
})
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With