протокол = http / 1.1 код = 409, сообщение = конфликт, ответ на NULL в модификации 2, но работает на Почтальоне - PullRequest
0 голосов
/ 24 апреля 2020

Я работаю над модулем регистрации и входа в приложение Android. Всякий раз, когда я вызываю API, используя Retrofit, я получаю Null в ответ. Но API работает на Почтальоне. Я просто запутался в том, что я делаю неправильно. Я просто новичок в вызовах API, поэтому, пожалуйста, помогите мне. Ошибка, с которой я сталкиваюсь, приведена ниже:

enter image description here

Можете ли вы, ребята, сказать мне причину или что я делаю неправильно? Спасибо.

Хорошо, я обновляю свой вопрос для лучшего понимания.

API, работающий в POST man:

https://stay-safe-api.azurewebsites.net/api/v1/users/register/public_user

Параметры:

"FullName" : "Test",
"Email" : "test@gmail.com",
"PhoneNumberCountryDialCode" : "+92",
"PhoneNumber" : "52512456",
"PhoneNumberCountryCode": "PK", 
"Gender" : "Male",
"Password" : "12345678",
"DisplayPicture" : "https://image.shutterstock.com/image-vector/user-icon-vector-260nw-393536320.jpg",
"Address" : "1123 west st",
"Role" : "PUBLIC_USER",
"CurrentLocation_CountryTitle" : "pakistan",
"CurrentLocation_CountryISOCode" : "PK",
"CurrentLocation_CityTitle" : "Lahore",
"CurrentLocation_Lat" : 25.1988,
"CurrentLocation_Long" : 55.2796

Поэтому, когда я запускаю это на почтальоне, я получаю такой ответ:

{
"data": {
    "FullPhoneNumber": "+9252512456",
    "Gender": "Male",
    "DisplayPicture": "https://image.shutterstock.com/image-vector/user-icon-vector-260nw-393536320.jpg",
    "CurrentLocation_CountryTitle": "pakistan",
    "CurrentLocation_CountryISOCode": "PK",
    "CurrentLocation_CityTitle": "Lahore",
    "CurrentLocation_Lat": 25.1988,
    "CurrentLocation_Long": 55.2796,
    "CurrentLocation_UpdatedAt": null,
    "RiskScore": 100,
    "ColorCode": "Green",
    "HealthStatus": "No Record of Potential Infection",
    "InfectionType": "COVID-19",
    "VerificationStatus": false,
    "_id": "5ea29debd40d080045d56da5",
    "FullName": "Test",
    "Email": "test@gmail.com",
    "PhoneNumberCountryCode": "PK",
    "PhoneNumberCountryDialCode": "+92",
    "PhoneNumber": "52512456",
    "Password": "$2b$10$nUhMWiq61cCLy5rn7Yd4d.vlxBXre64ESmge1zyja2BCsbRszxpzC",
    "Address": "1123 west st",
    "Role": "PUBLIC_USER",
    "location": {
        "type": "Point",
        "coordinates": [
            55.2796,
            25.1988
        ]
    },
    "UserCode": "SF2004248T4I",
    "updatedAt": "2020-04-24T08:06:03.758Z",
    "createdAt": "2020-04-24T08:06:03.758Z"
},
"message": "Successfully registered!"

}

Но когда я реализовал это в своем приложении. Я столкнулся с ошибкой, о которой упоминал выше. Поэтому мой код:

Интерфейс API:

public interface ApiInterface {

@POST("users/register/public_user")
Call<RegisterResponse> registerCall(@Body RegisterBody registerBody);}

Клиент API:

    public class ApiClient {

//    public static final String BASE_URL = "https://stay-safe-api.azurewebsites.net/api/v1/users/register/";
    private static Retrofit retrofit = null;


    public static Retrofit getClient() {
        if (retrofit == null) {
            retrofit = new Retrofit.Builder()
                    .baseUrl("https://stay-safe-api.azurewebsites.net/api/v1/")
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
        }
        return retrofit;
    }
}

Вызов API:

ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);

Call<RegisterResponse> call = apiInterface.registerCall(registerBody);

call.enqueue(new Callback<RegisterResponse>() {
    @Override
    public void onResponse(Call<RegisterResponse> call, Response<RegisterResponse> response) {

        registerResponse = response.body();

    }

    @Override
    public void onFailure(Call<RegisterResponse> call, Throwable t) {
        Toast.makeText(OTPScreen.this, "Fails", Toast.LENGTH_SHORT).show();
    }
});

Так что, когда Я запустил приложение после заполнения формы и получил ошибку, о которой упоминал выше.

...