[英]Retrofit returns 500 Internal server error
我正在嘗試使用 Retrofit 庫更新數據庫記錄。 postman 在相同數據下工作正常。 GET 數據也可以正常工作,但 PATCH 操作返回錯誤 500 內部服務器錯誤。
界面:
//@Headers("Content-Type: application/json")
@PATCH("usersapi/{id}")
Call<UserBank> updateUserBank(@Path("id") int id, @Body UserBank post);
主要活動:
retrofit = new Retrofit.Builder()
.baseUrl("https://<website>/api/")
// .addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
jsonCofyBizApi = retrofit.create(jsonCofyBizApi.class);
UserBank post = new UserBank(user_id, txtbankname.getText().toString());
Call<UserBank> call = jsonCofyBizApi.updateUserBank(user_id, post);
call.enqueue(new Callback<UserBank>() {
@Override
public void onResponse(Call<UserBank> call, Response<UserBank> response) {
UserBank postResponse = response.body();
和代碼的rest...
類/構造函數用戶銀行:
public class UserBank {
@SerializedName("user_id")
int user_id;
@SerializedName("bank_name")
String bank_name;
public UserBank(int user_id, String bank_name)
{
this.user_id = user_id;
this.bank_name = bank_name;
}
rest的代碼...
我看到了具有相同主題的其他線程,但沒有一個解決方案對我有用。 url 正在正確生成。
任何幫助表示贊賞。 問候, PD
問題已經解決了。 在指定端點的末尾添加“/”
@PATCH("usersapi/{id}")
Call<UserBank> updateUserBank(@Path("id") int id, @Body UserBank post);
@PATCH("usersapi/{id}/")
Call<UserBank> updateUserBank(@Path("id") int id, @Body UserBank post);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.