sad301
sad301

Reputation: 396

Navigate to URL with additional header

Is there anyway we can navigate (via <a/> click) to a URL with additional header in the request ? here's my code :

i have an <a href="#" id="aUsers"/> tag, and then i handle the onClick() event via JQuery :

$('#aUsers').click(function () {
  var spAuthData = sessionStorage.getItem('sp-auth-data');
  window.location.href = '/users.html?sp-auth-data' = spAuthData;
});

I want to put the spAuthData value in the authorization header, so i can have a clean URL

Upvotes: 4

Views: 7675

Answers (1)

Yeldar Kurmangaliyev
Yeldar Kurmangaliyev

Reputation: 34189

As far as I know, there is no way to manipulate HTTP headers with a plain url.

You can use headers parameter of jQuery AJAX request if it is suitable in your situation. For example, you can update the contents of some divs with AJAX HTML response.

$.ajax({
    url: '/users.html',
    headers: { 'Authorization': spAuthData }
}).done(function() 
{
});

Otherwise, it looks like you need to make some server-side changes.

But why don't you use cookies or something like this?
Authorization is used only by unauthorized users during authorization. In my opinion, sending this header on every request from the browser manually sounds bad. The best approach is to send this header once during authorization, create a user session and store it in cookies (as an access-token, forms ticket or whatever else).

Upvotes: 3

Related Questions