XHR returning net::ERR_METHOD_NOT_SUPPORTED error to PUT/POST requests

23 views
Skip to first unread message

Peter Bernhardt

unread,
Sep 13, 2014, 1:23:13 PM9/13/14
to ang...@googlegroups.com
I have an issue processing responses from a server to a PUT request (same happens with POST). Starts with the following CORS pre-flight request.

Request:

OPTIONS /open/Patient/1 HTTP/1.1
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Access-Control-Request-Method: PUT
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36
Access-Control-Request-Headers: accept, content-type
Accept: */*
DNT: 1
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8

Response:

HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 0
Date: Sat, 13 Sep 2014 16:58:28 GMT
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Content-Location, Location
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Headers: accept, content-type
Access-Control-Request-Method: GET, POST, PUT, DELETE
Server: Name of remote server

Then the actual request:

PUT /open/Patient/1 HTTP/1.1
Connection: keep-alive
Content-Length: 775
Pragma: no-cache
Cache-Control: no-cache
Accept: application/json+fhir, application/json, text/plain, */*
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36
Content-Type: application/json+fhir
DNT: 1
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8

The response is not processed by AngularJS, instead it reports the following error:

net::ERR_METHOD_NOT_SUPPORTED

The body of the response is empty, and the status is "0". Thing is, if I set a break point in the Chrome debugger and walk the call through to the AngularJS implementation of the XHR call, I DO get a successful response. Here's what I get in the response:

HTTP/1.1 200 OK
Connection: keep-alive
Content-Encoding: gzip
Content-Type: application/json+fhir; charset=UTF-8
Content-Length: 154
Date: Sat, 13 Sep 2014 17:13:35 GMT
Pragma: no-cache
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Content-Location, Location
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Server: Health Intersections FHIR Server

Here's the body of my code that sends the request using $http:

        function updateResource(resourceUrl, resource) {
            var deferred = $q.defer();
            $http.put(resourceUrl, resource)
                .success(function (data, status, headers, config) {
                    var results = {};
                    results.data = data;
                    results.headers = headers();
                    results.status = status;
                    results.config = config;
                    deferred.resolve(results);
                })
                .error(function (data, status) {
                    var error = { "status": status, "outcome": data };
                    deferred.reject(error);
                });
            return deferred.promise;
        }

Obviously this is a timing issue. The response from the server is prematurely processed by XHR. But why?

Thanks in advance for any help or suggestions for further investigation.

Peter Bernhardt

unread,
Sep 14, 2014, 10:34:32 AM9/14/14
to ang...@googlegroups.com
I've resolved this issue working with the developer of the server. Turns out there was an issue with the way the server handled connections. Resolved.

--
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/-Il3dgiM0FQ/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