How to get string response from Retrofit2?

前端 未结 10 1514
时光取名叫无心
时光取名叫无心 2020-12-01 07:44

I am doing android, looking for a way to do a super basic http GET/POST request. I keep getting an error:

java.lang.IllegalArgumentException: Unable to creat         


        
10条回答
  •  爱一瞬间的悲伤
    2020-12-01 07:47

        call.enqueue(new Callback() {
            @Override
            public void onResponse(@NonNull Call call, @NonNull Response response) {
                if (response.isSuccessful()) {
                    Gson gson = new Gson();
                    String successResponse = gson.toJson(response.body());
                    Log.d(LOG_TAG, "successResponse: " + successResponse);
                } else {
                    try {
                        if (null != response.errorBody()) {
                            String errorResponse = response.errorBody().string();
                            Log.d(LOG_TAG, "errorResponse: " + errorResponse);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
    
            @Override
            public void onFailure(@NonNull Call call, @NonNull Throwable t) {
            }
        });
    
        

    提交回复
    热议问题