跨源请求仅支持以下协议方案:http [英] Cross origin requests are only supported for protocol schemes: http

查看:156
本文介绍了跨源请求仅支持以下协议方案:http的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个常规的JavaScript问题,但是在使用Splunk JavaScript SDK的代码中会弹出...错误是:

This is a general JavaScript question but it pops up in this code which uses Splunk JavaScript SDK... the error is:

XMLHttpRequest无法加载文件:///C:/proxy/services/auth/login?output_mode = json.跨源请求仅支持以下协议方案:http,数据,chrome,chrome扩展名,https,chrome-extension-resource. jquery.min.js:4

XMLHttpRequest cannot load file:///C:/proxy/services/auth/login?output_mode=json. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource. jquery.min.js:4

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script type="text/javascript" src="json2.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="prettify.js"></script>
<script type="text/javascript" src="bootstrap.tabs.js"></script>
<script type="text/javascript" src="bootstrap.dropdown.js"></script>
<script type="text/javascript" src="jquery.placeholder.min.js"></script>
<script type="text/javascript" src="splunk.js"></script>

<script type="text/javascript" charset="utf-8">
console.log('a');
var http = new splunkjs.ProxyHttp("/proxy");
var service = new splunkjs.Service(http, {
    username: "admin",
    password: "Moravac123223",
    scheme: "https",
    host: "localhost",
    port: "8089",
    version: "5.0"
});
 console.log('b');
// First, we log in
service.login(function(err, success) {
    // We check for both errors in the connection as well
    // as if the login itself failed.
    if (err || !success) {
        console.log("Login failure. Please check your server hostname and authentication credentials.");
        done(err || "Login failed");
        return;
    } 

    // Now that we're logged in, let's get a listing of all the apps.
    service.apps().fetch(function(err, apps) {
        if (err) {
            console.log("There was an error retrieving the list of applications:", err);
            done(err);
            return;
        }

        var appsList = apps.list();
        console.log("Applications:");
        for(var i = 0; i < appsList.length; i++) {
            var app = appsList[i];
            console.log("  App " + i + ": " + app.name);
        } 

        done();
    });
});
</script>
</body>
</html>

推荐答案

我同意Charlietfl.如果您使用的是apache和/或IIS,那应该是一个非常快速的测试,以验证是否已修复它.

I agree with Charlietfl. If you have apache and/or IIS, it should be a pretty quick test to validate that this fixed it.

如果您是Web服务器的新手,请不要担心他们拥有 Xampp 从一个可执行文件设置您的整个LAMP堆栈.

If you are new to web-server's in general, have no fear they have applications like Xampp that setup your entire LAMP stack from one executable file.

由于您正在对自己的服务器进行身份验证,因此可能会(或不会)遇到此问题,但是我在运行本地RESTful应用程序时遇到了麻烦,并且挂起了后端使用的内容,我需要执行以下操作:setHeader ('Access-Control-Allow-Origin','*');到我回复的标题.

Since you are authenticating into your own server, you may(not) run into this, but I have had trouble with running local RESTful applications, and pending what you are using on the backend I needed to do something like this: setHeader('Access-Control-Allow-Origin', '*'); to the header of my response.

很明显,如果您决定创建某种企业级Web服务,则不需要这样的东西,但是对于本地测试,通常会避开我遇到的随机CORS问题.

Obviously you don't want something like this if you decide to create some sort of enterprise class web service, but for local testing, that generally gets around random CORS issues I have ran into.

祝您的网络应用程序好运!

Good luck with your web app!!

这篇关于跨源请求仅支持以下协议方案:http的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆