Friday 15 April 2011

Angularjs: Passing along a token using $resource? -


I am trying to pass with a token using the header along with my $ resource requests. Generally, you can do

  $ http.defaults.headers.common   

in .config, but when I apply for the first time I'm unaware of these bootstraps so I thought I do the following ... but my headers are not passing in the present ..

The token is currently hard coded, but once I do it If it is confirmed, it will come from the injection.

  var resource = $ resource ('http: // localhost: port / todos /: id', {port: ": 3001", id: '@ id'}, {{" Approved ":" app / luggage, version = 3 "," authorization ":" token token = 'xxxxxxxxx' "}}, update: {method: 'PUT'}}); Return processing;   

If I check intelligence, I do not see the acceptance or authorization header in my request.

I see a message in Fiddler but there are no headers. I was expecting.

Am I missing something here?

Any thoughts?

Thanks

First of all, nothing is wrong with your customer side code If you are not cross-requesting the original request (CORS - xhr requests for a different host / port than your script service), then it should work properly. Here is a non-corrosion PLKR example working with your code - you can verify that your custom headers are being sent:

If you have to make a cross original request then you have to make sure A browser that supports both CORS (IE & gt; = 10, the latest Chrome or Firefox) and that your server code correctly responds to the CORS preflight option request. This article explains that this is pretty good:

I have created another plunker example and it is working by setting up a server that responds to the following ()

ago - preflight option request

  request URL: http: // localhost: 8080 / todos request method: option    

server response

  HTTP / 1.1 200 OK access-control-permission-origin: * Access-control-permission-methods: obtain, access-control-off Keep the fear: authorization content-length: 0    

Next "real" request

  Request URL: http: // Localhost: 8080 / todos request method: Receive    

Feedback (note that access-control-moderator headers are also here):

  HTTP / 1.1 200 OK content-type: app / x-json; Charset = UTF-8 Access-Control-Permission-Origin: * Access-Control-Permission-Methods: Receive, Access-Control-Allow- Header: Authorization Content-Length: 13    

Response body:

  {"test": "OK"}     

No comments:

Post a Comment