Skip to content

Credentials #994

@LingLong

Description

@LingLong

Hello guys,
I'd set up a fake backend with https://jsonstub.com.
Then i try to get a response using restangular but it wont work.
Maybe you guys can help me!

(I know that the issue has something to do with cross-origin-request.)

This is my module config:

angular.module('crudApp').config(function($stateProvider, RestangularProvider) {

    //test restangularconfig
        RestangularProvider.setBaseUrl('http://jsonstub.com/api/entries/');        
        RestangularProvider.setDefaultHeaders({ 'Content-Type': 'application/json',
                                          'Access-Control-Allow-Credentials': 'true', 
                                          'JsonStub-User-Key': '121f02ff-d938-4c26-8c4c-6e3eae1ac468',
                                         'JsonStub-Project-Key': 'ea5d0a15-51b3-4b5b-834a-a9e96cb0228e'}); 

        RestangularProvider.setDefaultHttpFields({
            'withCredentials': true              
        }); 

And this is part of my controller:

app.controller('restTestCTRL',['$scope', 'Restangular', '$http', function($scope, Restangular, $http){

//Tests RestAngular     
//get       
$scope.getData = Restangular.all(':id')
$scope.allData = $scope.getData.getList().$object;          

I got the following Error :
XMLHttpRequest cannot load http://jsonstub.com/api/entries/:id. Credentials flag is 'true', but the 'Access-Control-Allow-Credentials' header is ''. It must be 'true' to allow credentials.

I am really at the end^^ because i set this header to true and i also tryed a couple of other things and headers but nothing works for me.

PS: if i take the example-code ($http) from jsonstub everything works fine.
code:

//GET single entry
            $http({
                url: 'http://jsonstub.com/api/entries/:id',
                method: 'GET',
                dataType: 'json', 
                data: '',         
                headers: {
                    'Content-Type': 'application/json',
                    'JsonStub-User-Key': '121f02ff-d938-4c26-8c4c-6e3eae1ac468',
                    'JsonStub-Project-Key': 'ea5d0a15-51b3-4b5b-834a-a9e96cb0228e'
                }
            }).success(function (data, status, headers, config) {
                alert('GET single entry: ' + JSON.stringify(data, null, 4));
            });  

If i try this there is no error and i got my exampledata from jsonstub.
No issue about cross-origin-shit or something like that. So what is the difference, i thought that restangular is also build around $http ?!

Thank you for your help !!!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions