REST api authentication through json

2019-05-19 10:23发布

问题:

I'm trying to do a simple REST api in a CakePhp app, using a REST plugin I found, which for Authorization uses http headers.

My question is, how can I supply through jQuery using json, a header like for example:

Authorization: TRUEREST username=wwwww&password=zzzzz&apikey=xxxxxyyyyyyy

回答1:

$.ajax({
  // ...
  beforeSend: function(x) {
    x.setRequestHeader('Authorization', 'TRUEREST username=wwwww&password=zzzzz&apikey=xxxxxyyyyyyy');
  },
  // ...
});

Docs: http://api.jquery.com/jQuery.ajax/



标签: jquery json rest