1

I'm getting a problem when I try to call my WebApi, I need to send in a request header the authorization credentials, but, I'm not getting it up.

My resquest header need to be like this image of the request header generated by my REST tester

Authorization:Basic dXNlcm5hbWU6cGFzc3dvcmQ=

But, when I try to set it on Angular using this code block

$http.defaults.headers.Authorization = 'Basic ' + credentials;
return $http.post('http://localhost:2703/api/Authenticate');

Or this

return $http.post('http://localhost:2703/api/Authenticate', {
    headers: { 'Authorization': 'Basic ' + credentials }
});

My request header became like this one

Access-Control-Request-Headers: accept, authorization

Can someone tell me what am I doing wrong? Any help will be appreciated. :)

1
  • I've found the problem, I guess. When I added headers to my POST call, the method was changed to OPTIONS, I'm using cross domain. Trying to find out how to fix it. Commented Oct 16, 2015 at 15:41

2 Answers 2

1

You can do something like this:

var header = {headers: {'Authorization': 'Basic ' + credentials}}
$http.post(url, payload, header)
    .success(function (data) {
       //stuff
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Doing this the header continues the same. The authorization was added to "Access-Control-Request-Headers". I guess that I need to add a new header named "Authorization". I really don't know what need to do.
0

I couldn't resolve my problem using a cross domain request, so, I've configure my Web Api and Web App in the same domain. Doing this, I can change the headers normally and send a post request as I need.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.