このトピックに関する他の記事もたくさんありますが、残念ながら解決策のどれも私のために働いていませんでした。apiへのPOSTコールでブロックされたクロスオリジンリクエスト
私はApache Red Hat 7.2をApache 2.4(httpd)で実行しています。私はlocalhostとして直接サーバー上で作業しています。 APIはPythonに基づいており、私は少し経験があります - 私はgithub mozilla http observatoryからプログラムをダウンロードしました。
私は数時間異なる設定を試していますが、この問題について進歩を遂げておらず、今、さらなる支援を求めています。
メインページPOSTがここhttp://localhost
あるJS(アヤックス)が
A POST XHRコールがに行われている前に、私は午前の前に:http://localhost:57001/api/v1/scanここ
function loadTLSObservatoryResults(rescan, initiateScanOnly) {
'use strict';
var rescan = typeof rescan !== 'undefined' ? rescan : false;
var initiateScanOnly = typeof initiateScanOnly !== 'undefined' ? initiateScanOnly : false;
/*var SCAN_URL = 'https://tls-observatory.services.mozilla.com/api/v1/scan';
var RESULTS_URL = 'https://tls-observatory.services.mozilla.com/api/v1/results';
var CERTIFICATE_URL = 'https://tls-observatory.services.mozilla.com/api/v1/certificate';*/
var SCAN_URL = 'http://localhost:57001/api/v1/scan';
var RESULTS_URL = 'http://localhost:57001/api/v1/results';
var CERTIFICATE_URL = 'http://localhost:57001/api/v1/certificate';
// if it's the first scan through, we need to do a post
if (Observatory.state.third_party.tlsobservatory.scan_id === undefined || rescan) {
// make a POST to initiate the scan
$.ajax({
data: {
rescan: rescan,
target: Observatory.hostname
},
initiateScanOnly: initiateScanOnly,
dataType: 'json',
method: 'POST',
error: function() { errorResults('Scanner unavailable', 'tlsobservatory') },
success: function (data) {
Observatory.state.third_party.tlsobservatory.scan_id = data.scan_id;
if (this.initiateScanOnly) { return; }
loadTLSObservatoryResults(); // retrieve the results
},
url: SCAN_URL
});
私のhttpd.confです
basicall yがちょうどこの行が含まれていました。
RewriteEngine On
Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
Header always set Access-Control-Max-Age "1000"
Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]
私は、Apacheを再起動しているが、私は、デベロッパーコンソールで同じ警告を参照してください:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:57001/api/v1/scan. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
LoadModule headers_module modules/mod_headers.so
は私の.htaccessファイルがあります
なぜ 'python'タグがありますか? –