【问题标题】:can't POST to github v3 API无法发布到 github v3 API
【发布时间】:2012-04-07 17:30:12
【问题描述】:

我正在尝试通过 javascript 创建一个公共要点。我没有使用任何身份验证 - 这都是客户端。

var gist = {
    "description": "test",
    "public": true,
    "files": {
        "test.txt": {
            "content": "contents"
        }
    }
};

$.post('https://api.github.com/gists', gist, function(data) {
});

以上代码抛出 400:错误请求 - 解析 JSON 时出现问题。但是,我的 JSON 是有效的。有什么想法吗?

【问题讨论】:

标签: javascript json github gist


【解决方案1】:

啊哈 - 我无法将对象传递给 $.post。需要先字符串化:

var gist = {
    "description": "test",
    "public": true,
    "files": {
        "test.txt": {
            "content": "contents"
        }
    }
};

$.post('https://api.github.com/gists', JSON.stringify(gist), function(data) {});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-02
    • 1970-01-01
    • 1970-01-01
    • 2015-04-27
    • 1970-01-01
    • 2019-05-10
    • 2023-03-28
    相关资源
    最近更新 更多