0

I have tried below code on different ways using angualrjs.but there is no reflection on connection timeout in request header as well as application flow.i have went through many angular js sites. but no output.

   angular.module('MyApp', [])
        .config(['$httpProvider', function($httpProvider) {
       $httpProvider.defaults.timeout = 5000;
     }]);
Shamil
  • 727
  • 1
  • 9
  • 17
  • possible duplicate of [How to set a global http timeout in AngularJs](http://stackoverflow.com/questions/15015416/how-to-set-a-global-http-timeout-in-angularjs) – Cristik May 19 '15 at 07:44
  • yeah, even i went through that link also..but unable to find the solution. – Shamil May 19 '15 at 07:53

1 Answers1

1

It looks like you're writing to the wrong object (defaults instead of defaults.headers).

The defaults can also be set at runtime via the $http.defaults object in the same fashion. For example:

module.run(function($http) {  
   $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w' });
}

from here. Try to do it this way.

Or when your request is sent (same source as before a few lines below):

var req = {
 method: 'POST',
 url: 'http://example.com',
 headers: {
   'Content-Type': undefined
 },
 data: { test: 'test' }
}

$http(req).success(function(){...}).error(function(){...});
orange
  • 7,755
  • 14
  • 75
  • 139
  • have you tried this one??. can u able to see the reflection of the above code in your connection requets header.. – Shamil May 19 '15 at 08:03
  • but in angular js the global way of setting connection timeout is looks like angular.module('MyApp', []) .config(['$httpProvider', function($httpProvider) { $httpProvider.defaults.timeout = 5000; }]); – Shamil May 19 '15 at 08:04
  • No, I haven't tried it. You have an open project, so it should be easy to change. Provide the full running code of your example and I try it out myself. – orange May 19 '15 at 08:04
  • u can get the sample url.just try to hit that service with your requested timeout. – Shamil May 19 '15 at 08:05
  • https://gist.github.com/adnan-i/5014277 i hope this would be fine. let me try this one.. but it's look like hardcoding the value. – Shamil May 19 '15 at 08:08