Channa
Channa

Reputation: 3747

Error when accessing localhost api in chrome net::ERR_INSECURE_RESPONSE

I was trying to access api running in localhost using angular $resourses, chrome console gives me error saying ERR_INSECURE_RESPONSE.

I tried disabling web security in chrome. still same error. here is the angular factory that i used. How can I bypass this error and test my app.

    ImpactPortal.factory('apiFactory', function ($resource) {
    return $resource('https://localhost:8443/mifosng-provider/api/v1/client_impact_portal', {}, {
        query: {
            method: 'GET',
            params: {},
            isArray: true
        }
    })
});

Upvotes: 3

Views: 15699

Answers (4)

Shawn Azdam
Shawn Azdam

Reputation: 6170

Only try this:

Go to https://[your-domain].com and then chrome block you with the famous page:

Your connection is not private

So go down to ADVANVCED and then proceed.

Your certificate is probably self-signed.

Remember to do that for each Chrome session.

Upvotes: 2

Avik
Avik

Reputation: 1220

You must authenticate first and then send each request along with the auth token.

I am using RestAngular so my settings might look a little different from what you are working on.

This will go in your application config :-

RestangularProvider.setDefaultHeaders({ 'X-Mifos-Platform-TenantId': 'default' });

and something like this will go in your controller/service

var login = Restangular.all('authentication?username=mifos&password=password').post().then(function(user) {
   console.log(user);
 }, function() {
  console.log("There was an error saving");
 });

Upvotes: 1

Narek Mamikonyan
Narek Mamikonyan

Reputation: 4611

Enabling CORS in Angular.js

var myApp = angular.module('myApp', [
    'myAppApiService']);

myApp.config(['$httpProvider', function($httpProvider) {
        $httpProvider.defaults.useXDomain = true;
        delete $httpProvider.defaults.headers.common['X-Requested-With'];
    }
]);

A server supporting CORS must respond to requests with several access control headers:

Access-Control-Allow-Origin: "*"

By default, CORS requests are not made with cookies. If the server includes this header, then we can send cookies along with our request by setting the withCredentials option to true.

Access-Control-Allow-Credentials (optional)

If we set the withCredentials option in our request to true, but the server does not respond with this header, then the request will fail and vice versa.

Upvotes: 6

v2solutions.com
v2solutions.com

Reputation: 1439

Error 501 (net::ERR_INSECURE_RESPONSE) - 501 Not Implemented

The server either does not recognize the request method, or it lacks the ability to fulfill the request. Usually this implies future availability (e.g., a new feature of a web-service API).

Can you confirm that curl request is working fine

curl -k --user [email protected]:password https://localhost:8443/mifosng-provider/api/v1/client_impact_portal

If it is working fine:

ImpactPortal.factory('apiFactory', function ($resource) {
    return $resource('https://localhost:8443/mifosng-provider/api/v1/client_impact_portal', {}, {
        query: {
            method: 'JSONP',
            params: {},
            isArray: true
        }
    })
});

Try following this tutorial that consume an external API: http://www.toptal.com/angular-js/a-step-by-step-guide-to-your-first-angularjs-app

Upvotes: -2

Related Questions