2017-02-14 9 views
0

$ http.postを実行しようとしていますが、この応答でこのエラーが発生します。

XMLHttpRequestはhttp://XXXXXXXXX:2222/server/api/v1/controllersをロードできません。プリフライトの応答が無効なHTTPステータスコード403

を持っている私のすべては、CORSによってその障害が、私は成功しませんこの問題を解決しようとするインターネット・サイスで読みます。

ここは私の$ http.postメソッドです。

 // Set the Content-Type 
     $http.defaults.headers.post["Content-Type"] = "application/json"; 

     // Delete the Requested With Header 
     delete $http.defaults.headers.common['X-Requested-With']; 



     var config = { 
      method: 'POST', 
      headers: {'Content-Type': 'application/json; charset=utf-8'} 
     } 

     $http.post("http://XXXXXXXXX:2222/server/api/v1/controllers", objToSave , config) 
      .then(function successCallback(response) { 
      // this callback will be called asynchronously 
      // when the response is available 
      console.log(response) 
      }, function errorCallback(error) { 
      // called asynchronously if an error occurs 
      // or server returns response with an error status. 
      console.log(error) 
      }); 

私はAngular v1.5.5を使用しています。私はあなたが私を助けることができると思います

よろしく!

+0

CORSエラー=> **側 – Weedoze

+0

この役立ちますあなたの**サーバー上のCORSの設定を確認してください:http://stackoverflow.com/a/38333662/1225328を? – sp00m

答えて

2

クロムは、最初のサーバーが適切に応答するかどうかをチェックするためのプリフライトリクエストを送信します。サーバがそのプリフライト要求を適切に処理すると、元の要求がクロムに​​よって送信されます。サーバーの要求ハンドラーヘッダーの下に行を追加してください。

Access-Control-Allow-Origin: * 
関連する問題