0

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;
 });
Dhruv Gohil
  • 842
  • 11
  • 34
  • Have you tested it? – libcthorne May 27 '16 at 06:48
  • Yeah,response is null.Is that right way to pass header?@cthorne – Dhruv Gohil May 27 '16 at 06:51
  • Response is *null* or *undefined* ? And yes, that looks correct.. https://docs.angularjs.org/api/ng/service/$http – Mico May 27 '16 at 06:52
  • here is the list of http headers https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers. `ApiKey` and `UserAddress` are not among them. If it is some data that you want to send then encode it in the url or pass it as json data – Avantika Saini May 27 '16 at 06:53
  • I think this issue is same as [link](http://stackoverflow.com/questions/11876777/set-http-header-for-one-request) – Vishwa May 27 '16 at 06:54
  • You should be using `.then` and `.catch` to handle a response object. The `.success` method is **deprecated** and spreads the response into several arguments for the handler function. – georgeawg May 27 '16 at 08:09
  • After using .then and .catch , I am getting **qwe = Object {data: null, status: -1, config: Object, statusText: " "}** What is the problem ? what does that mean ? what I am doing wrong ?@georgeawg – Dhruv Gohil May 27 '16 at 09:19

1 Answers1

0

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

Elayaraja Dev
  • 208
  • 3
  • 6