response.body (). getResponseCode () == 200 - нет ответа - PullRequest
0 голосов
/ 06 февраля 2020

ответ всегда поднимается ie Неправильный ответ от сервера.

Я пробовал разные способы, но ответа не было. И когда я пытался получить getCode 200, получилось NPE, прежде чем я использовал тот же метод в другом случае я мог получить ответ ... но в этом случае я не обращал внимания на reposn. в то время как входные данные и бэкэнд верны на мой взгляд. Я надеюсь, что мои друзья могут помочь мне, спасибо

эта функция getresponse post.

       HashMap<String, String> params = new HashMap<>();
        params.put("id_member",sharedPrefManager.getSpIdMember() );
        params.put("id_product_category", txt_id_product_category.getText().toString());
        params.put("id_product",  txt_id.getText().toString());
        params.put("number", txt_number.getText().toString());
        params.put("list_id_company", mitraStringBuilder.toString());

        Call<ResponseCicilan> getCicilan = mApiService.getCicilanProduct(params);

        getCicilan.enqueue(new Callback<ResponseCicilan>() {
            @Override
            public void onResponse(Call<ResponseCicilan> call, Response<ResponseCicilan> response) {
                if(response.body()!=null){
                    ResponseCicilan responseCicilan = response.body();
                    String content ="";
                    if(response.body().getResponseCode()==200){
                        content+= responseCicilan.getData().getProductMeta().getIdProduct();

                    }else {
                        content+=responseCicilan.getMessage();
                    }
                    Log.d("jajal", "onResponse: login res"+content);
//
//                    Toast.makeText(TransactionSelectMitra.this, ""+response.message(), Toast.LENGTH_LONG).show();
//                    Log.d("bismillah", "onResponse: fail "+response.code());
//                    return;
                }

                Log.d("bismillah", "onResponse: success"+response.code()+"  "+response);

                if(response.body().getResponseCode()==200){
                    String content="";
//                    _loginButton.setEnabled(false);
                    ResponseCicilan responseCicilan = response.body();
                    content += "code:"+ response.code();
                    content += "token:"+ responseCicilan.getData().toString();

                    Log.d("bismillah", "onResponse: login res"+content);
                } else {
                    Toast.makeText(TransactionSelectMitra.this, "Invalid response from server", Toast.LENGTH_SHORT).show();
                }

            }

            @Override
            public void onFailure(Call<ResponseCicilan> call, Throwable t) {
                Toast.makeText(TransactionSelectMitra.this, "Invalid response from server", Toast.LENGTH_SHORT).show();
            }
        });
}

этот интерфейс API

@FormUrlEncoded
@POST("ApiMobile/getDatatenor")
Call<ResponseCicilan> getCicilanProduct(@FieldMap HashMap<String, String> params);

ответ. java

public class ResponseCicilan{

    @SerializedName("response_code")
    private int responseCode;

    @SerializedName("data")
    private Data data;

    @SerializedName("message")
    private String message;

    public void setResponseCode(int responseCode){
        this.responseCode = responseCode;
    }

    public int getResponseCode(){
        return responseCode;
    }

    public void setData(Data data){
        this.data = data;
    }

    public Data getData(){
        return data;
    }

    public void setMessage(String message){
        this.message = message;
    }

    public String getMessage(){
        return message;
    }
}

enter image description here

...