How to change http header using (). get and (). post()?

Asked

Viewed 348 times

0

Very briefly I need to send a jwt token in the http header of the requests, as I can change the headers of jQuery requests $.post() and $.get()?

Example of how I do using Curl by prompt:

curl -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhcHAudGVjbWFuLmNvbSIsInVzZXJuYW1lIjoiSmVhbiBGcmVpdGFzIiwiZW1haWwiOiJoZW5yaXF1ZWszQGxpdmUuY29tIiwiYWNsIjpbInJoIiwiZmluYW5jZWlybyIsImNvbWVyY2lhbCIsImVuZ2VuaGFyaWEiLCJhZG1pbmlzdHJhdGl2byJdfQ==.kq4nJJYBTbjWwtbmu\/wB+EXilDHHPr8es6mXpsXEVMs=" http://meuapp.com/jwt

1 answer

0


You can use something like:

$.ajax({
  url: "http://meuapp.com/jwt",
  dataType: 'json',
  success: function(data, status) {
    return console.log("Dados", data);
  },
  beforeSend: function(xhr, settings) { xhr.setRequestHeader('Authorization','Bearer ' + token); } 
});

Jquery ajax Setting

Browser other questions tagged

You are not signed in. Login or sign up in order to post.