I am creating a food booking App in Android.I need to send my order details which includes multiple product details and user details to back end which is created in P H P.I am using retrofit for web service calling.How to send these data in Json format to back end using retrofit.Do i need to create model class for saving data.
Asked
Active
Viewed 100 times
-2
-
1what have you tried ? – yogesh lokhande Dec 22 '17 at 04:41
-
1Refer this : https://stackoverflow.com/questions/30180957/send-post-request-with-params-using-retrofit – Rahul Khurana Dec 22 '17 at 04:44
-
stuck on confirm order page, the page has product details – niyas nazar Dec 22 '17 at 04:48
-
1*"Do i need to create model class for saving data"* depends on what is your response data – Navneet Krishna Dec 22 '17 at 04:59
1 Answers
1
In API Interface
@Headers("Content-Type:application/json")
@POST("auth/login")
Call<String> login(@Body RequestBody requestBody);
and when you make service call
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put(Constants.Params.EMAIL, etEmail.getText().toString());
jsonObject.put(Constants.Params.PASS_WORD, etPassword.getText().toString());
} catch (JSONException e) {
}
ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);
final Call<String> loginCall = apiInterface.login(RequestBody.create(MediaType.parse("multipart/form-data"), jsonObject.toString));

Vishal G. Gohel
- 1,008
- 1
- 16
- 31