AngularJS Adding a header to the $http.get

前端 未结 2 1689
有刺的猬
有刺的猬 2021-01-21 11:57

I\'m trying to add the \'Authorization\' header containing a token for future HTTP request. Retrieval of the token seems to be fine however when making a get request it fails wi

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-21 12:08

    I'm not sure I understand your problem completely as you did not provide what you call

    httpConfig

    If you're struggling to declare the headers, try making the get request like this:

    $http({
      method: 'GET',
      url: YOUR_URL,
      headers: {
        'Content-Type': 'application/json',
        'Authorization': AUTH_STRING_HERE
      }
    }).then(function (response) { ... });
    

    You can add any headers you like in the headers object there.

提交回复
热议问题