0
每當我嘗試發送一個post請求,我得到500錯誤。獲取請求正常工作。通過郵遞員的郵寄請求也可以正常工作,所以在服務器端沒有問題。問題是什麼?
請求代碼:Retrofit post request: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: [email protected]
D/myLogs: [email protected]
D/myLogs: 500
D/myLogs: [email protected]
發佈採購信息聲明:
@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;
}
}
可惜的是,它並不能幫助 –
嘗試發送參數FormUrlEncoded –
你的意思是用頭而不是身體? –