简体   繁体   中英

How to add header in $http.get in angularjs

Hi I am workinig on Angularjs application.I am passing some items in header.Is that correct ? I have my code as below:

$http({
     method: 'GET',
     url: 'http://api/v1/fund/get?major=true',
     headers: {
         'Content-Type': 'application/json',
         'ApiKey': 'asdsd5369a7c19e34e9b205d6f916837sds90927esdsd80556b959e2ac8a8f3',
         'UserAddress': '111.111.5.45'
     }
 }).success(function (response) {
     $scope.data = response.data;
     $scope.Temp = response.statusText;;
 }).error(function (qwe) {
     var temp = qwe.statusText;
 });

What ever you have written in header is not all is correct. Content type is only correct. You have to send Apikey and user address in data.

$http({
     method: 'GET',
     url: 'http://api/v1/fund/get?major=true',
     data: {'ApiKey': 'asdsd5369a7c19e34e9b205d6f916837sds90927esdsd80556b959e2ac8a8f3',
         'UserAddress': '111.111.5.45'}
     headers: {'Content-Type': 'application/json'}
 }).success(function (response) {
     $scope.data = response.data;
     $scope.Temp = response.statusText;;
 }).error(function (qwe) {
     var temp = qwe.statusText;
 });

If you have any queries Please refer below url: https://docs.angularjs.org/api/ng/service/ $http

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM