Модифицированный почтовый запрос возвращает нулевое значение? - PullRequest
0 голосов
/ 24 марта 2020

Я хочу вызвать Retrofit через POST-запрос, но его API-интерфейс возвращает нулевое значение. Как я могу решить эту проблему?

            final double aLat = lat;
            final double aLan = lan;
            String c = country;
            String LebalStr = Lebal.getText().toString().trim();
            Retrofit retrofit = new Retrofit.Builder()
                        .baseUrl("http://2.52.365/abc-api/api/User/")
                        .addConverterFactory(GsonConverterFactory.create())
                        .build();
            JSONObject params = new JSONObject();
            JSONObject params1=new JSONObject();
            JSONObject countryID=new JSONObject();
            try {
                params.put("UserID", 3);
                countryID.put("countryID",1);

                params.put("AddressLabel", LebalStr);

                params.put("Latitude", aLat);
                params.put("Longitude", aLan);
                params.put("country",countryID);                                   
                params1.put("UserAddressTypeId", 1);
                params.put("UserAddressType",params1);
            }catch (Exception ex){}

            Call<String> call = retrofit.create(Api.class)
                    .senddata(params);
            call.enqueue(new Callback<String>() {
                @Override
                public void onResponse(Call<String> call, Response<String> response) {
                    String LebalStr = Lebal.getText().toString().trim();
                    Intent intent = new Intent();
                    intent.putExtra("location",LebalStr);
                    setResult(RESULT_OK, intent);
                    finish();
                    Toast.makeText(getApplicationContext(), "Done"+response.body(), Toast.LENGTH_SHORT).show();

                }
                @Override
                public void onFailure(Call<String> call, Throwable t) {
                    Toast.makeText(getApplicationContext(), "Failed"+t.getMessage(), Toast.LENGTH_SHORT).show();

                }
            });



        }catch(Exception g){
            Toast.makeText(getApplicationContext(), ""+g.getMessage(),Toast.LENGTH_SHORT).show();
        }

    }

} catch (Exception e) {
    e.printStackTrace();
}

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

@POST("AddAddressByUserID")
Call<String> senddata(@Body JSONObject params);

Что не так в код выше?

...