删除呼叫返回415不支持的媒体类型

时间:2019-12-15 18:06:57

标签: android node.js heroku kotlin

我已经在nodejs中编写了一个API调用,用户可以在其中删除其帐户:

router.delete('/deleteAccount', checkAccessToken, (req, res, next) => {


User.find({ username: req.tokenData.username })
    .exec()
    .then(user => {
        if (user.length < 1) {
            return res.status(404).json({
                message: 'Username does not exist'
            });
        }

                User.deleteOne({ username: req.tokenData.username }, function (err, res) {
                    if (err) throw err;

                });
                UserSprint.deleteMany({ username: req.tokenData.username }, function (err, res) {
                    if (err) throw err;

                });

                return res.status(200).json({
                    message: "Successfully deleted"
                });

    });

});

在与Postman和本地进行测试时,此调用工作正常,但在将API部署到我的Heroku实例后,该调用返回415 Unsupported Media Type

我在Android中的通话

@DELETE("user/deleteAccount")
fun deleteAccount(@Header(value = "authorization") authorization: String): Observable<Response<String>>

这就是我建立请求的方式

 val request = original.newBuilder()
                .header("Content-Type", "application/json;charset=utf8")
                .header("Accept", "application/json;charset=utf-8")
                .method(original.method, original.body)
                .build()

1 个答案:

答案 0 :(得分:1)

在Content-Type中定义的字符集不正确。 Here's the list of all valid charset values.

对于UTF-8,请将标头更改为:application/json;charset=utf-8