改造返回 500 内部服务器错误

时间:2021-03-25 06:25:23

标签: android json api retrofit retrofit2

我正在尝试使用 Retrofit 库更新数据库记录。邮递员可以很好地处理相同的数据。 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();

和其余的代码...

类/构造函数用户库:

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

其余代码...

我看到了其他主题相同的主题,但没有一个解决方案对我有用。网址正确生成。

任何帮助表示赞赏。 问候, PD

1 个答案:

答案 0 :(得分:0)

问题解决了。在指定端点的末尾添加'/'

 @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);