如何将数据发布到Web服务

时间:2018-04-25 10:04:15

标签: javascript jquery ajax sapui5

问题描述: - 我试图调用不同域的Web服务(即系统之间没有本地连接),所以我收到错误: - "无法加载https://sap.atlassian.net/:响应预检无效(重定向)"

var username = "pra@sap.com";
        var password = "Sa8";
        $.ajax({
            type: 'POST',
            data: data1,
            url: 'https://sap.atlassian.net',
            dataType: 'json',
            contentType: "application/json",
            crossDomain: true,
            ProcessData: true,
            headers: {
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Allow-Credentials": "true",
                "Access-Control-Allow-Methods": "POST, GET, PUT, DELETE, OPTIONS",
                "Access-Control-Allow-Headers": "accept, X-Custom-Header, x-requested-with, X-Auth-Token, Content-Type"
            },
            beforeSend: function(xhr) {
                xhr.setRequestHeader("X-Atlassian-Token", "no-check");
                xhr.setRequestHeader('Authorization', "Basic" + btoa(username + ":" + password));
            },
            success: function(data) {
                console.log("success");
            },
            error: function(e) {
                console.log(e);
            }
        });

1 个答案:

答案 0 :(得分:0)

首先,您可能需要仔细检查网址。必须有一些相对的URL。

这与预检相关。见https://www.gyanblog.com/gyan/39-explaining-issue-response-preflight-request-doesnt-pass-access-control-check

你能发布详细的堆栈跟踪吗?

PS:公开使用您的用户名/密码总是不好的做法。你应该立即更改你的密码!