I have been having issues using the latest version of Chrome, AngularJS 
1.2.0 rc3, and CORS set up with Apache via .htaccess.

.htaccess settings:

Header set Access-Control-Allow-Origin *
Header set Access-Control-Allow-Methods "GET,PUT,POST,DELETE,OPTIONS,PATCH"
Header set Access-Control-Allow-Headers "Content-Type,Accept"

When a page is loaded and we perform an action on our API (different domain 
than our site) that involves a GET/POST, everything works fine - forever. 
However, if the action we take performs a PUT/DELETE or other less-common 
verb, we have a 10 second window to perform these requests after which all 
future PUT/DELETE/etc requests receive no response. Here is a sample 
timeline to help make this more clear:

0s - page loads
1s - user clicks button that triggers a DELETE
1.2s - OPTIONS preflight request is sent, 200 OK received
1.3s - DELETE request is sent, 200 OK received
...
10.2s - user clicks button that triggers a DELETE
10.3s - DELETE request is sent and server hangs up - no response received 
(preflight request must be cached, as it is not sent again)

A sample successful preflight OPTIONS request is pasted below:

Request URL:https://api.example.com/stuff/i/want
Request Method:OPTIONS
Status Code:200 OK

Request Headers
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:accept, content-type
Access-Control-Request-Method:PUT
Cache-Control:no-cache
Connection:keep-alive
Host:api.example.com
Origin:https://www.example.com
Pragma:no-cache
Referer:https://www.example.com/my/page
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) 
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36

Query String Parameters
access_token:*****

Response Headers
Access-Control-Allow-Headers:Content-Type,Accept
Access-Control-Allow-Methods:GET,PUT,POST,DELETE,OPTIONS,PATCH
Access-Control-Allow-Origin:*
Connection:Keep-Alive
Content-Length:194
Content-Type:application/json;charset=utf-8
Date:Thu, 23 Jan 2014 17:25:33 GMT
Keep-Alive:timeout=5, max=97
Server:Apache
Set-Cookie:ROUTEID=.0; path=/
Via:1.1 balancer
X-Powered-By:PHP/5.3.27-1ubuntu3.6

I have made changes to our .htaccess settings (such as setting a specific 
value for Access-Control-Allow-Origin) to verify that everything is working 
as expected, and have found no issues there. Open to any and all 
ideas/suggestions. Thanks for reading!

-Walter

On Monday, August 12, 2013 9:14:50 PM UTC-4, john tigernassau wrote:
>
> our rest server works with CURL, not with Angular http.   Any help 
> appreciated
>
> We've tried every CORS option we can find but angular still reports an 
> error with different origin
>
> Node Express running on port 3026:
>
> app.post('/api/account', function(req,res) {
>   //res.header("Access-Control-Allow-Origin","http://localhost:3025";);
>   res.header("Access-Control-Allow-Origin","*");
>   res.header("Access-Control-Allow-Headers","X-Requested-With");
>   res.header("Access-Control-Allow-Methods","GET, POST");
>   ....
>
> Our CURL test posts data just fine into our Node Express server
>
> curl -i -X POST http://localhost:8026/api/account -d 
> '{"accountname":"test", ....
> "password":"xxx"}' -H "Content-Type: application/json"
>
>
> angular running on port 3025:
>
> angular config: (doesn't work with / without)
>
> app.config(['$httpProvider', function($httpProvider) {
>         $httpProvider.defaults.useXDomain = true;
>         delete $httpProvider.defaults.headers.common['X-Requested-With'];
>     }
> ]);
>
> angular controller:
>
>   $scope.subscribe = function() {
>     var resturl = 'http://localhost:3026/api/account';
>     var jsondata = JSON.stringify($scope.account);
>     $http({
>       method : 'POST',
>       url    : resturl,
>       data   : $scope.account,
>       headers: {'Content-Type':'application/json'}
>     }).
>       success(function(data){....
>
> angular error msg:
>
> XMLHttpRequest cannot load http://localhost:3026/api/account. 
> Origin http://localhost:3025 is not allowed by 
> Access-Control-Allow-Origin. 
> localhost/:1 error
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to