通过Javascript Ajax请求将问题发布到Github存储库

时间:2018-09-21 12:06:33

标签: github xmlhttprequest

我正在尝试通过Javascript客户端在Github存储库中创建问题。我的代码就是这样

const github = `https://api.github.com/repos/${owner}/${repo}/issues`;

const msg = JSON.stringify({
    "title": `problem with record id: ${recId}`,
    "body": "something is wrong in Houston",
    "assignee": "flooba",
    "milestone": 1,
    "labels": [
        "images"
    ]
});

const x = new XMLHttpRequest();
x.open('POST', github, true);
x.onreadystatechange = function() {
    if (x.readyState == 4) {

        // show status message, all good
    }
};
x.setRequestHeader("Content-type", "application/json");
x.setRequestHeader("Authorization", "Basic " + btoa("username:password")); //**
x.send(msg);

[**]用户名和密码自然是:repo的信誉。

尝试上面的代码时,我得到http422。建议?

注意:在实际的工作代码中,我将凭据放在服务器端,并从Web客户端调用服务器端进程。

0 个答案:

没有答案