2014-09-13 40 views
1

我有一個問題處理從服務器響應PUT請求(同樣發生在POST)。從以下CORS飛行前請求開始。AngularJS:XHR返回net :: ERR_METHOD_NOT_SUPPORTED錯誤PUT/POST請求

請求:

OPTIONS /open/Patient/1 HTTP/1.1 
Host: remoteserver.com 
Connection: keep-alive 
Pragma: no-cache 
Cache-Control: no-cache 
Access-Control-Request-Method: PUT 
Origin: http://myclient 
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 
Referer: http://myclient/patient/2JT 
Accept-Encoding: gzip,deflate,sdch 
Accept-Language: en-US,en;q=0.8 

響應:

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 

然後實際的請求:

PUT /open/Patient/1 HTTP/1.1 
Host: remoteserver.com 
Connection: keep-alive 
Content-Length: 775 
Pragma: no-cache 
Cache-Control: no-cache 
Accept: application/json+fhir, application/json, text/plain, */* 
Origin: http://myclient 
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 
Referer: http://myclient/patient/2JT 
Accept-Encoding: gzip,deflate,sdch 
Accept-Language: en-US,en;q=0.8 

的響應不是由AngularJS處理,而不是將其報告以下錯誤:

net :: ERR_METHOD_NOT_SUPPORTED

響應的主體爲空,狀態爲「0」。事情是,如果我在Chrome調試器中設置了一個斷點,在完成代碼之後,我會得到一個成功的響應。下面是我的迴應得到:

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 
Content-Location: http://remoteserver/open/Patient/1/_history/6 
Server: Health Intersections FHIR Server 

這裏是我的代碼的身體將使用$ 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; 
} 
+0

我已經解決了與服務器開發人員合作的問題。事實證明,服務器處理連接的方式存在問題。解決。 – PeterB 2014-09-14 14:34:40

回答

0

我已經解決了這個問題與服務器的開發工作。事實證明,服務器處理連接的方式存在問題。解決。