繁体   English   中英

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

[英]Retrofit post request: 500 internal server error

每次尝试发送发帖请求时,都会出现500错误。 获取请求可以正常工作。 通过邮递员发布请求也可以正常工作,因此在服务器端没有问题。 问题是什么?

请求代码:

    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;
}

}

通过邮递员索取结果

去掉 / 。 因为改型Baseurl以/结尾。 所以您的网址现在就像baseurl // api / comments / add / text

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM