【问题标题】:Accessing ProcessMaker BPM framework's APIs from external apllication从外部应用程序访问 ProcessMaker BPM 框架 API
【发布时间】:2017-07-11 06:55:46
【问题描述】:

我已按照 PM 文档 (http://wiki.processmaker.com/3.1/OAuth_2.0) 中的教程进行操作,但未能成功访问访问令牌。 目前我正在使用 PM 的试用版,我想访问我的 java 应用程序 js 文件中的 API,但浏览器返回以下错误“XMLHttpRequest cannot load 'myPMServerAddress' has been blocked by CORS policy : 请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问源“http://localhost:8100”。”。

有什么帮助吗?? 我在 (User Applications -> +New) 表单的网站框中注册了我的应用服务器 (http://localhost:8100),我的代码如下所示:

var restServer = 'https://trial.processmaker.com/';
var workspace = 'sysmyWorkspace/';
var jqxhr = $.ajax({
    type: "POST",
    url:  restServer + workspace + 'oauth2/token',      
        data: {
        grant_type   : 'password',
        scope        : '*',
        client_id    : 'myClientId',
        client_secret: 'myClientSecret',
        username     : 'admin',
        password     : 'myPassword'
    }
})
    .done( function(data) {
        if (data.error) {
            alert("Error in login!\nError: " + data.error +    "\nDescription: " + data.error_description);
        }
        else if (data.access_token) {                
           alert("data access token received!");              
            var d = new Date();
            d.setTime(d.getTime() + 60*60*1000);
            document.cookie = "access_token="  + data.access_token  + "; expires=" + d.toUTCString();
            document.cookie = "refresh_token=" + data.refresh_token; //refresh token doesn't expire
        }
        else {
            alert(JSON.stringify(data, null, 4)); 
        }
    })
    .fail(function(data, statusText, xhr) {
        alert("Failed to connect.\nHTTP status code: " + xhr.status + ' '   + statusText);
    });    
}); 

【问题讨论】:

标签: ajax rest cors business-process-management processmaker


【解决方案1】:

您需要在客户端禁用 CORS

对于 Ubuntu: google-chrome --disable-web-security --user-data-dir

对于 Windows 女士: 进入命令提示符并进入 Chrome.exe 所在的文件夹并键入

chrome.exe --disable-web-security

我可以毫无错误地测试它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-19
    • 2011-04-07
    • 2013-05-25
    • 2015-12-02
    相关资源
    最近更新 更多