2017-09-08 24 views
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; 
} 

}

Request result via Postman

回答

3

刪除/。因爲改造Baseurl以/結束。所以烏爾網址是現在這個樣子的BaseURL // API /評論/添加/文本

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

可惜的是,它並不能幫助 –

+0

嘗試發送參數FormUrlEncoded –

+0

你的意思是用頭而不是身體? –