改装后请求:500内部服务器错误

时间:2017-09-08 21:07:52

标签: java android retrofit retrofit2

每次我尝试发送帖子请求时,都会收到500错误。获取请求工作正常。通过postman发布请求也很好,所以在服务器端没有问题。有什么问题?

请求代码:

    HseDayApi hseDayApi = HseDayApi.retrofit.create(HseDayApi.class);
    ApiPostComment comment = new ApiPostComment();
    comment.setAuthor("Author");
    comment.setContent("Test");
    comment.setEventid(123);
    Call<ResponseBody> postComment = hseDayApi.postComment(comment);
    postComment.enqueue(new Callback<ResponseBody>() {
        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            Log.d("myLogs", response.toString());
            Log.d("myLogs", String.valueOf(response.errorBody()));
            Log.d("myLogs", String.valueOf(response.code()));
            Log.d("myLogs", response.toString());
        }

        @Override
        public void onFailure(Call<ResponseBody> call, Throwable t) {

        }
    });

日志说这个

D/myLogs: retrofit2.Response@a1089f6
D/myLogs: okhttp3.ResponseBody$1@d57e1f7
D/myLogs: 500
D/myLogs: retrofit2.Response@a1089f6

发布请求声明:

@POST("/api/comments/add/text")
Call<ResponseBody> postComment(@Body ApiPostComment comment);

请求代码类:

public class ApiPostComment {
private int eventid;
private String author;
private String content;

public void setEventid(int eventid) {
    this.eventid = eventid;
}

public void setContent(String content) {
    this.content = content;
}

public int getEventid() {
    return eventid;
}

public String getAuthor() {
    return author;
}

public String getContent() {
    return content;
}

public void setAuthor(String author) {
    this.author = author;
}

}

Request result via Postman

1 个答案:

答案 0 :(得分:4)

  

删除/。作为改造Baseurl以/结尾。所以你的url现在像baseurl // api / comments / add / text

@POST("api/comments/add/text")<-------- change
Call<ResponseBody> postComment(@Body ApiPostComment comment); 
相关问题