rahul uday
rahul uday

Reputation: 131

Not able to set request headers to my ajax request

I'm trying to make an ajax call to service, my service api expects a Request Header for Authorization to give the response Here is my JS code

var settings = {
       url: "http://localhost:8080/codebluet-war/service/codeblue/facility",
       method: "GET",
       headers: {
           "Authorization": "oauthtoken"",
       }
   }
$.ajax(settings).done(function (response) {
  console.log(response)
});

I have added the Authorization headers in my code but still I'm getting 401 unauthorized request error.is there any other thing that I need to add in my settings?

Upvotes: 0

Views: 167

Answers (1)

antonku
antonku

Reputation: 7665

If you are using OAuth 2.0 you should prefix the token value with Bearer word:

headers: {
    "Authorization": "Bearer yourTokenValue",
}

With OAuth 1.0, it's a little bit more complicated since you need to send a set of parameters instead of a single token. Therefore, you may want to consider using a jQuery compatible OAuth library for this purpose.

Upvotes: 1

Related Questions