Request method (GET) turns into OPTIONS

68 views
Skip to first unread message

Andres Felipe Solarte López

unread,
Oct 23, 2014, 1:15:51 PM10/23/14
to ang...@googlegroups.com
i have a REST client but when y try to do a request the GET method turns into OPTIONS and Always i have 404 Unauthorized error, i tried the same with Postman and everything worked well, here are the code :

rentingApp.factory("AutoCompleteService", ["$http", function ($http) {
        return {
            search: function (term) {
                return $http({
                    method: "GET",
                    url: host_base_url + 'site/suggestCity',
                    headers: {
                        'Access-Control-Allow-Origin': '*',
                        'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
                        'Access-Control-Allow-Headers': 'Content-Type, X-Requested-With'
                    },
                    params: {
                        "term": term
                    },
                });
            }
        };
    }]);


and i have an HttpInterceptor , here is the code:

rentingApp.factory('myHttpInterceptor', function ($q) {
    return {
        'request': function (config) {

            config.headers["Authorization"] = api_id;

            return config || $q.when(config);
        },
        'requestError': function (rejection) {
            return $q.reject(rejection);
        },
        'response': function (response) {
            return response;
        },
        'responseError': function (rejection) {
            return $q.reject(rejection);
        }
    };
}).config(function ($httpProvider) {
    $httpProvider.interceptors.push('myHttpInterceptor');
});



for more details you can view the rest client in http://as-webs.com/rest_rentingcarz/#/


Thank you all 

Adrian Lynch

unread,
Oct 23, 2014, 4:55:14 PM10/23/14
to ang...@googlegroups.com
It looks like you're setting request headers to get work with CORS but these are headers that need to be set on the server as response headers.

Postman doesn't impose the same restrictions as the browser proper. It's an app so it's loser on what it can do.

Do you control site at this URL, host_base_url + 'site/suggestCity'?

Adrian

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

ravi kumar

unread,
Oct 24, 2014, 6:42:09 AM10/24/14
to ang...@googlegroups.com


Hi,

   I think the server need to be started,it looks like the server is off.

Thanks
Ravi 

Andres Felipe Solarte López

unread,
Oct 24, 2014, 10:31:42 AM10/24/14
to ang...@googlegroups.com
Hi Ravi, the server is already started

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/C01dlaKwLAA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.

To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.



--
Andrés Felipe Solarte
Desarrollador Web
Tel.: 726 24 76
Cel.: 321 233 38 62

Sander Elias

unread,
Oct 25, 2014, 1:24:32 AM10/25/14
to ang...@googlegroups.com
Hi Andres,

This is more a server problem then it is an AngularJS problem. You need to enable CORS properly on your server.
Almost anything you need to know about CORS is on the site I linked. 

If you still have questions, don't hesitate to ask them here!

Regards
Sander

Andres Felipe Solarte López

unread,
Oct 25, 2014, 4:25:10 PM10/25/14
to ang...@googlegroups.com
Thank you Sandler ! 

I am on the website now, hope it help me.

Thank you again.

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/C01dlaKwLAA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages