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;
     }]);
2
  • possible duplicate of How to set a global http timeout in AngularJs Commented May 19, 2015 at 7:44
  • yeah, even i went through that link also..but unable to find the solution. Commented May 19, 2015 at 7:53

1 Answer 1

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(){...});
Sign up to request clarification or add additional context in comments.

5 Comments

have you tried this one??. can u able to see the reflection of the above code in your connection requets header..
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; }]);
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.
u can get the sample url.just try to hit that service with your requested timeout.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.