在改造2中使用响应代码500获得空响应

时间:2019-03-06 22:38:29

标签: android retrofit2

我正在实现一个应用程序,其中有一个要编辑的用户配置文件,因此我将所有用户输入作为字符串获取,并使用翻新版2将其发送到服务器,我尝试了很多次代码,只有其中之一100次尝试正常,其余的我都得到响应值为500的空响应

在这里您可以看到我的代码:

这是界面

public interface ApiInterface {

    @POST("edit/profile")
    @FormUrlEncoded
    Call<AuthModel> editProfile (@Field("api_token") String api_token,
                                   @Field("profilePic") String profilePic,
                                 @Field("name") String name,
                                 @Field("email") String email,
                                 @Field("phoneNo") String phoneNo,
                                 @Field("state") String state,
                                 @Field("city") String city,
                                 @Field("age") String age,
                                 @Field("sex") String sex,
                                 @Field("lastBooking") String lastBooking,
                                 @Field("hostel") String hostel,
                                 @Field("roomNumber") String roomNumber,
                                 @Field("status") String status);
}

这是AuthModel

public class AuthModel {

    @Expose
    @SerializedName("api_token")
    private String api_token;
    @Expose
    @SerializedName("api_token_status")
    private String api_token_status;
    @Expose
    @SerializedName("status")
    private String status;
    @Expose
    @SerializedName("message")
    private String message;


    public String getApi_token() {
        return api_token;
    }

    public String getMessage() {
        return message;
    }

    public String getApi_token_status() {
        return api_token_status;
    }

    public String getStatus() {
        return status;
    }
}

这是ApiClient

public class ApiClient {

    public static final String BASE_URL = "http://www.kyz.com/api/";
    private static Retrofit retrofit = null;


    public static Retrofit getClient() {
        if (retrofit==null) {

            Gson gson = new GsonBuilder()
                    .create();

            retrofit = new Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create(gson))
                    .build();
        }
        return retrofit;
    }
}

这是我发出请求的方法

public void editProfileRequest (final Context context, String api_token, String profilePic, String name, String email, String phoneNo, String state,
                                String city, String age, String sex, String lastBooking, String hostel, String roomNumber, String status) {

    apiInterface = ApiClient.getClient().create(ApiInterface.class);
    Call<AuthModel> call = apiInterface.editProfile(api_token, profilePic, name, email, phoneNo, state, city, age, sex,
            lastBooking, hostel, roomNumber, status);
    call.enqueue(new Callback<AuthModel>() {
        @Override
        public void onResponse(Call<AuthModel> call, Response<AuthModel> response) {
            AuthModel result = response.body();
            if(result != null) {
                String status = result.getStatus();
                String msg = result.getMessage();
                if(status.equals("true")) {
                    Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
                }
            } else {
                try {
                    //Toast.makeText(context, response.errorBody().string() , Toast.LENGTH_LONG).show();
                    Log.v("errorBody", response.errorBody().string());
                    Log.v("respCode", String.valueOf(response.code()));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        @Override
        public void onFailure(Call<AuthModel> call, Throwable t) {
            Toast.makeText(context, t.toString(), Toast.LENGTH_LONG).show();
        }
    });
}

我想与您分享的最后一件事是response.errorBody()

Illuminate\Database\QueryException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry &#039;barsoum@email.com&#039; for key &#039;users_email_unique&#039; (SQL: update `users` set `name` = Barsoum, `email` = barsoum@email.com, `city` = Asyut, `bloodType` = B+, `hospital` = St Louis, `roomNumber` = 555, `numOfPackets` = 6, `status` = Preparing for Surgery, `updated_at` = 2019-03-06 22:02:37 where `id` = 30) in file /home/keesbdco/public_html/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 664
Stack trace:
  1. Illuminate\Database\QueryException-&gt;() /home/keesbdco/public_html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
  2. PDOException-&gt;() /home/keesbdco/public_html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:483
  3. PDOStatement-&gt;execute() /home/keesbdco/public_html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:483
  4. Illuminate\Database\Connection-&gt;Illuminate\Database\{closure}() /home/keesbdco/public_html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:657
  5. Illuminate\Database\Connection-&gt;runQueryCallback() /home/keesbdco/public_html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:624
  6. Illuminate\Database\Connection-&gt;run() /home/keesbdco/public_html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:490
  7. Illuminate\Database\Connection-&gt;affectingStatement() /home/keesbdco/public_html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:423
  8. Illuminate\Database\Connection-&gt;update() /home/keesbdco/public_html/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2508
  9. Illuminate\Database\Query\Builder-&gt;update() /home/keesbdco/public_html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:780
 10. Illuminate\Database\Eloquent\Builder-&gt;update() /home/keesbdco/public_html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:693
 11. Illuminate\Database\Eloquent\Model-&gt;performUpdate() /home/keesbdco/public_html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:608
 12. Illuminate\Database\Eloquent\Model-&gt;save() /home/keesbdco/public_html/app/Http/Controllers/Api/ProfileController.php:57
 13. App\Http\Controllers\Api\ProfileController-&gt;edit() /home/keesbdco/public_html/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
 14. call_user_func_array() /home/keesbdco/public_html/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
 15. Illuminate\Routing\Controller-&gt;callAction() /home/keesbdco/public_html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:45
 16. Illuminate\Routing\ControllerDispatcher-&gt;dispatch() /home/keesbdco/public_html/vendor/laravel/framework/src/Illuminate/Routing/Route.php:212
 17. Illuminate\Routing\Route-&gt;runController() /home/keesbdco/public_html/vendor/laravel/framework/src/Illuminate/Routing/Route.php:169
 18. Illuminate\Routing\Route-&gt;run() /home/keesbdco/public_html/vendor/laravel/framework/src/Illuminate/Routing/Router.php:665
 19. Illuminate\Routing\Router-&gt;Illuminate\Routing\{closure}() /home/keesbdco/public_html/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
 20. Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}() /home/keesbdco/public_html/app/Http/Middleware/typeapi.php:19
 21. App\Http\Middleware\typeapi-&gt;handle() /home/keesbdco/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
 22. Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}() /home/keesbdco/public_html/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
 23. Illuminate\Routing\Pipeline-&gt;Illuminate\Routing\{closure}() /home/keesbdco/public_html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php:41
 24. Illuminate\Routing\Middleware\SubstituteBindings-&gt;handle() /home/keesbdco/public_html/vendor/laravel/framework/src/I

请帮助我解决此问题,我认为这不是服务器端错误,因为1%的尝试可以正常工作,而99%的尝试可以解决此问题。请帮助,谢谢

1 个答案:

答案 0 :(得分:0)

响应代码500Internal Server Error,这意味着它的侧面有问题。

有关HTTP共振状态代码的信息,请参见this link