首页 文章

AngularJS POST json到SilverStripe API

提问于
浏览
3

我使用SilverStripe模块(here)编写了一个非常基本的API,并在构建它时使用Postman和Advanced REST Client chrome扩展进行测试,因此我知道 endpoints 有效 .

现在,当尝试访问 endpoints (POST json)时,API告诉我未设置所需的值 . 我做了一些挖掘,并将Postman的请求头与使用Firebug的Angular的请求头进行了比较 . 唯一值得注意的差异是Postman中Content-Type的 Headers 是:

“应用程序/ JSON”

对于Angular来说:

“application / json; charset = UTF-8”

这是Angular POST的代码(非常基本):

notebookFactory.addNotebook = function(title) {

    var notebook = "Testing Title 23!";
    var message = {
        Title: notebook
    };

    return $http({
        url: 'api/notebook',
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
            data: message
    });     
};

API错误说:“JSON属性 Title 是必需的”

这可能有所作为吗?我已经尝试将charset = UTF-8添加到Postman中的Content-Type的末尾并收到相同的错误 . 有没有办法从Angular POST Headers 中删除charset?

如果您需要更多信息并提前致谢,请告诉我们!

1 回答

相关问题