简体   繁体   English

Azure机器学习 - CORS

[英]Azure Machine Learning - CORS

I've searched for hours for this and can't find a single thing that answers the question. 我已经为此搜索了几个小时,找不到回答问题的单一内容。 I've created and published a new Azure Machine Learning service, and have created an endpoint. 我创建并发布了一个新的Azure机器学习服务,并创建了一个端点。 I can call the service using the Postman REST CLient, but accessing it via a JavaScript webpage returns a console log saying that CORS is enabled for the service. 我可以使用Postman REST CLient调用该服务,但是通过JavaScript网页访问它会返回一个控制台日志,说明为该服务启用了CORS。 Now, for the life of me, I can't figure out how to disable CORS for Azure Machine Learning services. 现在,就我而言,我无法弄清楚如何为Azure机器学习服务禁用CORS。 Any help would be much appreciated, thanks! 任何帮助将不胜感激,谢谢!

Currently, we don't support disabling CORS on API side but you can either use the above option or you can use the API management service to disable CORS. 目前,我们不支持在API端禁用CORS,但您可以使用上述选项,也可以使用API​​管理服务来禁用CORS。 The links below should help you with this 以下链接可以帮助您

Here are the links: step by step guide, also this video on setting headers, and this doc on policies. 以下是链接: 分步指南,此视频关于设置标题,以及策略文档

API Management service allow CORS by enabling it in the API configuration page API管理服务通过在API配置页面中启用CORS来允许CORS

You have to start your browser with --disable-web-security ( Chrome that is ). 您必须使用--disable-web-security (Chrome)启动浏览器。 Here's some jQuery that allowed me to call the service AFTER re-starting my browser with --disable-web-security: 这里有一些jQuery允许我在使用--disable-web-security重启我的浏览器后调用该服务:

$(document).ready(function () {
    var ajaxData = "-- the request body ";
    var serviceUrl = "https://ussouthcentral.services.azureml.net/workspaces/00e36959fc3e4673a32eae9f9b184346/--whatever";

    $.ajax({
        type: "POST",
        url: serviceUrl,
        data: ajaxData,
        headers: {
            "Authorization": "Bearer --API KEY HERE--",
            "Content-Type": "application/json;charset=utf-8"
        }
    }).done(function (data) {
        console.log(data);
    });
});

That returned the data. 这返回了数据。 NOTE: Be sure you see that warning in Chrome. 注意:请务必在Chrome中看到该警告。 I didn't at fist, because some Chrome processes were still running in the background. 我没有抓住,因为一些Chrome进程仍然在后台运行。 After killing those, restarting with that flag, seeing the message, it worked. 在杀死那些之后,重启那个标志,看到消息,它就有效了。 ( Chrome v40.something ) (Chrome v40.something)

See: https://stackoverflow.com/a/6083677/896697 请参阅: https//stackoverflow.com/a/6083677/896697

Just an excerpt from the Azure ML Book (one may find it useful): 只是摘自Azure ML Book(可能会发现它很有用):

This CORS restriction really means that if you wish to fully exploit Azure Machine Learning web services for deployment, testing, and production for a wide variety of (web) clients, you will need to host your own server-side applications. 此CORS限制实际上意味着,如果您希望完全利用Azure机器学习Web服务进行各种(Web)客户端的部署,测试和生产,则需要托管自己的服务器端应用程序。 You basically have two choices. 你基本上有两个选择。

  1. Host a web application, such as an ASP.NET webpage, and invoke the Azure Machine Learning web service server-side to conform to the current Azure Machine Learning CORS restrictions. 托管Web应用程序(如ASP.NET网页),并调用Azure机器学习Web服务服务器端以符合当前Azure机器学习CORS限制。
  2. Host your own web service that does provide CORS support and can in turn invoke the Azure Machine Learning web service on behalf of a wide variety of web and mobile clients via modern protocols and data formats like REST and JSON. 托管您自己的Web服务,该服务提供CORS支持,并可以通过现代协议和数据格式(如REST和JSON)代表各种Web和移动客户端调用Azure机器学习Web服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM