我正嘗試使用在瀏覽器中運行的jQuery腳本將數據寫入Splunk。我已經在我的「inputs.conf」文件如下:使用Splunk獲取CORS錯誤
crossOriginSharingPolicy = *
但是,我得到的錯誤是:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://myserver.myco.com:8088/services/collector/event.
(Reason: missing token 'content-type' in CORS header 'Access-Control-Allow-Headers' from CORS preflight channel).
我還沒有找到一個方法來設置「訪問 - Control-Allow-Headers'來自Splunk。
這裏是JS代碼片段,雖然我不知道它甚至需要顯示它(註釋行的事情,我在絕望中嘗試過,但他們並沒有區別):
var dfr = $.ajax({
url: config.endpoint,
method: 'post',
// headers: {
// "Access-Control-Allow-Origin" : "*",
// "Access-Control-Allow-Methods" : "GET,POST,PUT,DELETE,OPTIONS",
// "Access-Control-Allow-Headers": "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"
// },
// crossDomain: true,
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", header);
},
data: JSON.stringify({ event: post }),
contentType: "application/json; charset=utf-8",
dataType: "json"
});
有什麼建議嗎?我是否需要通過代理訪問Splunk?