@GET
Call<List<User>> getMyFriends(@Header(GlobalDeclarationsRetrofit.HEADER_AUTHORIZATION) String lang, @Url String url, "Need to send a json object here");
Any help should be greately appreciated..
You can pass parameter by @QueryMap Retrofit uses annotations to translate defined keys and values into appropriate format. Using the @Query("key") String value annotation will add a query parameter with name key and the respective string value to the request url .
change your call interface @Body parameter to String, don't forget to add @Headers("Content-Type: application/json") : @Headers("Content-Type: application/json") @POST("/api/getUsers") Call<List<Users>> getUsers(@Body String rawJsonString); now you can post raw json.
You can send parameter as hashmap or pojo, the parameters will send as JSON object. as:
@POST("user/checkloc")
Call<CheckLocation> checkLocation(@Body Location location);
Here location is pojo object as:
public class Location {
String lat,lng;
public Location(String lat, String lng) {
this.lat = lat;
this.lng = lng;
}
}
and it will send parameters as JSON object as:
D/OkHttp﹕ --> POST /api/index.php/user/checkloc HTTP/1.1
D/OkHttp﹕ {"lat":"28.4792293","lng":"77.043042"}
You can also send parameter as Hashmap:
@POST("user/checkloc")
Call<CheckLocation> checkLocation(@Body HashMap<String, String> hashMap);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With