Android的改造返回状态500内部服务器错误 [英] Android Retrofit return status 500 internal server error

查看:1800
本文介绍了Android的改造返回状态500内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用改造这样让所有的书籍,并删除所有的书。

I am using Retrofit like this to get all the books and delete all the books.

 @GET("/books")
    BookListResponse getAllBooks();
    @DELETE("/clean")
    Response deleteAllBooks();

但是,一个错误状态500(内部服务器错误)返回。 我测试了使用Chrome RESTful客户端应用程序,这两个宁静的电话,它们工作正常。

But an error status 500 (internal server error) was returned. I tested these two restful calls using Chrome restful client app and they work properly.

不过,如果我只是想获得一本书或删除这样的一本书

However, if I just want to get one book or delete one book like this

 @GET("books/1")
    BookResponse getOneBook();
    @DELETE("books/1")
    Response deleteOneBook();

他们也能正常工作。

They can work properly.

所以我不知道这是服务器问题还是我错过了一些东西?

So I am not sure if that's the server issue or I have missed something?

感谢你了。

推荐答案

这是语义的只是一个问题:当你说你的服务器,请删除书,但你不说这书要删除,服务器不知道该怎么做(发生这种情况,当你发送一个DELETE来/书籍)。因此,错误500但是,当你说请用ID 1删除书,现在的服务器知道怎么做(发生这种情况,当你发送一个DELETE来/书籍/ 1)。

This is just a matter of semantics: when you say to your server "Please delete book", but you don't say which book you want to delete, the server don't know what to do (this happens when you send a DELETE to /books). Hence the error 500. But when you say "Please delete book with id 1", now the server knows what to do (this happens when you send a DELETE to /books/1).

这是确定工作方式,如果你设置你的服务器是这样,但我从来没有见过任何REST服务,删除特定模型的所有记录。同样,如果你codeD服务器这样就ok了,只要确保请求到达服务器,你所希望的方式。

It is ok to work that way if you setup your server like this, but I've never seen any REST service to delete ALL records of a particular model. Again, if you coded your server this way it is ok, just make sure the request is reaching the server the way you want.

毕竟,如果你有一个500错误,请检查您的服务器。这个问题是不是在Android方面,肯定。

After all, if you got a error 500, check your server. The problem isn't in the Android side, definitely.

这篇关于Android的改造返回状态500内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆