私はAngularJSとNodeJS(API)アプリケーションを持っています。 私はすでにCORS()nodejsライブラリを使って私のNodeJSでCORSを有効にしていました。ファイアウォールの背後にあるAngularJS NodeJS Corsの問題
CORSを有効にするために必要なヘッダーも含めました。
会社のコンピュータからウェブサイトにアクセスした場合にのみCORSの問題が発生しています。それは私のパーソナルコンピュータからうまく動作します。私が間違っていることについて誰もが私を案内してくれますか?助けや提案をお願いします。
Chromeコンソールログ:
--------------------ヘッダー----------------- ----
一般:
Request URL:www.example.com:81/api/getdata
Request Method:GET
Status Code:503 Service Unavailable
Remote Address:111.111.11.111:81
レスポンスヘッダ:
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:close
Content-Length:973
Content-Type:text/html; charset=UTF-8
Expires:Thu, 01 Jan 1970 00:00:00 GMT
P3P:CP="CAO PSA OUR"
Pragma:no-cache
のリクエストヘッダ:
Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Host:www.example.com:81
Origin:http://www.example.com
Referer:http://www.example.com/
User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
--------------------応答:--------------- -----
<html>
<head>
<title>Web Page Blocked</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<meta name="viewport" content="initial-scale=1.0">
</head>
<body bgcolor="#e7e8e9">
<div id="content">
<h1>Web Page Blocked</h1>
<p>Access to the web page you were trying to visit has been blocked in accordance with company policy. Please contact your
system administrator if you believe this is in error.</p>
<p><b>User:</b> </p>
<p><b>URL:</b> www.example.com:81/api/getdata </p>
<p><b>Category:</b> unknown </p>
</div>
</body>
</html>
ブラウザのコンソールエラー:
XMLHttpRequest cannot load http://www.example.com:81/api/getdata . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://www.example.com ' is therefore not allowed access. The response had HTTP status code 503.
------ EDIT ----- ここでは、CORS(ある)私は渡しています。
app.options('*',cors());
app.use(function (req, res, next){
res.header("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, PATCH, DELETE");
res.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, PATCH, DELETE");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With,Content-type, Accept");
res.header("Access-Control-Allow-Credentials", true);
next();
});
中に存在していない理由を説明することができ、いくつかのヘッダーを削除またはブロックということです。 – Duncan
応答をありがとう、私は別のポートで試してみるだろう。 – user3479754