我已经在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()
答案 0 :(得分:1)
在Content-Type中定义的字符集不正确。 Here's the list of all valid charset values.
对于UTF-8,请将标头更改为:application/json;charset=utf-8
。