【问题标题】:Ajax Header Request "X-openIDM-Reauth-Password" not workingAjax 标头请求“X-openIDM-Reauth-Password”不起作用
【发布时间】:2017-07-03 04:44:58
【问题描述】:

我有一个 openIDM 程序,当用户提交更新新密码时,它会显示“X-openIDM-Rauth-Password”,其中包括我需要重新输入的旧密码。以下是 openidm 端的屏幕截图。

所以,我有自己的 UI,我是来自 javascript ajax 方面的请求,并带有以下 ajax 调用。

$.ajax({
        contentType: "application/json; charset=UTF-8",
        datatype: 'json',
        url: targetHost+"openidm/managed/user/"+userId,     
        xhrFields: {
            withCredentials: true,
        },
        headers: {
                    "X-Requested-With":"XMLHttpRequest" ,
                    "X-OpenIDM-Reauth-Password": oldPassword
                },
        crossDomain:true,

        data: JSON.stringify(data),
        type: 'PATCH',   
        success:function(result) {
            console.log("success");
            swal({
                title: updateSuccessMsgs.formSubmit.slogan,
                text: updateSuccessMsgs.formSubmit.success,
                type: "success"
            }, function() {
                window.location = "my-profile.html";
            });
        },
        error:function (error){
            sweetAlert(updateErrorMsgs.updateError.slogan, updateErrorMsgs.updateError.fail, "error");
            console.log(error);
        }
     });

它给我这个错误。

XMLHttpRequest cannot load http://localhost:9090/openidm/managed/user/09096425-4ff1-42d4-8a4d-3a6b5004afca. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.

谁能解释一下为什么?欣赏它。

【问题讨论】:

  • lookup CORS - 服务器没有发送标头以允许客户端“访问”资源 - 注意:因为这是一个 preflight错误,可能只是服务器不了解如何处理 OPTIONS 请求方法
  • 您还需要在服务器上添加Access-Control-Allow-Origin:* 标头。

标签: javascript ajax rest openidm


【解决方案1】:

我找到了解决方案。我尝试在 servletfilter-cors.json 中再添加一个值,如下所示。我在“allowedHeaders”中添加了“X-OpenIDM-Reauth-Password”的值,它是成功的。

{
    "classPathURLs" : [ ],
    "systemProperties" : { },
    "requestAttributes" : { },
    "scriptExtensions" : { },
    "initParams" : {
        "allowedOrigins" : "*",
        "allowedMethods" : "GET,POST,PUT,DELETE,PATCH",
        "allowedHeaders" : "accept,x-openidm-password,x-openidm-nosession,x-openidm-username,content-type,origin,X-OpenIDM-Reauth-Password,x-requested-with",
        "allowCredentials" : "true",
        "chainPreflight" : "false"
    },
    "urlPatterns" : [
        "/*"
    ],
    "filterClass" : "org.eclipse.jetty.servlets.CrossOriginFilter"
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-16
    • 1970-01-01
    • 1970-01-01
    • 2014-11-03
    • 1970-01-01
    • 2015-12-21
    • 2012-11-28
    • 2014-12-28
    相关资源
    最近更新 更多