Bonjour j'ai créé un API en laravel pour modifier le profil d'utilisateur et ça marche bien avec Postman, au niveau android j'ai créé une Interface.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
public interface UpdateProfile {
 
    String UPDPRO ="http://IP/Projet/public/api/";
    @FormUrlEncoded
    @POST("users/{id}")
    Call<String> UpdateUsers(
            @Path("id") int id,
            @Field("name") String name,
            @Field("adresse") String adresse,
            @Field("prenom") String prenom,
            @Field("email") String email,
            @Field("numtel") String numtel
    );
}
et mon profil fragment
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
 
public class Profile_Fragment extends Fragment  implements View.OnClickListener {
    private EditText editTextName, editTextPrenom,editTextAdresse,editTextEmail,editTextTel;
    private static View view;
    private static Button buttonupdate;
    public Profile_Fragment(){
 
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view= inflater.inflate(R.layout.profile_fragment, container, false);
        initViews();
        setListeners();
        return view;
        }
    private void initViews() {
        editTextName = view.findViewById(R.id.editTextName);
        editTextPrenom = view.findViewById(R.id.editTextPrenom);
        editTextAdresse=view.findViewById(R.id.editTextAdresse);
        editTextEmail = view.findViewById(R.id.editTextEmail);
        editTextTel = view.findViewById(R.id.editTextTel);
        buttonupdate = view.findViewById(R.id.buttonupdate);
    }
    private void setListeners() {
        buttonupdate.setOnClickListener(this);
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.buttonupdate:
                updateUsers();
                break;
        }
    }
    private void updateUsers() {
        int id = getId();
        String name = editTextName.getText().toString().trim();
        String prenom = editTextPrenom.getText().toString().trim();
        String email = editTextEmail.getText().toString().trim();
        String adresse = editTextAdresse.getText().toString().trim();
        String numtel = editTextTel.getText().toString().trim();
 
        if (name.isEmpty()) {
            editTextName.setError("Nom doit être rempli");
            editTextName.requestFocus();
            return;
        }
        if (prenom.isEmpty()) {
            editTextPrenom.setError("Prenom doit être rempli");
            editTextPrenom.requestFocus();
            return;
        }
        if (adresse.isEmpty()) {
            editTextAdresse.setError("Adresse doit être rempli");
            editTextAdresse.requestFocus();
            return;
        }
        if (email.isEmpty()) {
            editTextEmail.setError("Email doit être rempli");
            editTextEmail.requestFocus();
            return;
        }
        if (numtel.isEmpty()) {
            editTextTel.setError("Numero téléphone doit être rempli");
            editTextTel.requestFocus();
            return;
        }
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(UpdateProfile.UPDPRO)
                .addConverterFactory(ScalarsConverterFactory.create())
                .build();
        UpdateProfile api = retrofit.create(UpdateProfile.class);
        Call<String> call = api.UpdateUsers(id,name,prenom,adresse,email,numtel);
 
        call.enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
 
                if (response.isSuccessful()) {
                    if (response.body() != null) {
                        Log.i("Responsestring", response.body().toString());
                        Log.i("onSuccess", response.body().toString());
 
                        String jsonresponse = response.body().toString();
 
                        try {
                            JSONObject jsonObject = new JSONObject(jsonresponse);
 
                            if (jsonObject.getString("status").equals("success")) {
                                Toast.makeText(getActivity(), "Update Successfully!", Toast.LENGTH_SHORT)
                                        .show();
                            } else if (jsonObject.getString("status").equals("error")) {
                              /*  new CustomToast().Show_Toast(getActivity(), view,
                                        " " + jsonObject.getString("message"));*/
                                Toast.makeText(getActivity(), "Update failed!", Toast.LENGTH_SHORT)
                                        .show();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
 
                    }
 
                }
            }
 
            @Override
            public void onFailure(Call<String> call, Throwable t) {
                Toast.makeText(getContext(), "Server invalid \n" + t.getMessage(), LENGTH_LONG).show();
            }
        });
 
 
    }
 
 
}
lorsque j’insère des nouveaux informations pour l'utilisateur j'aperçoit Update failed. J'estime que le problème vient du id de l'utilisateur.