How To Post Json Object Using Retrofit
i wanted to post the json object using retrofit. i have created following interface: public interface syncinter { @POST('url') void sync_data(@Body JSONObject ordObj, Callback<
Solution 1:
i was able to post it using TypedInput
declare the api as shown below
@PUT(ServerEndPoint)
void callApi(@Body TypedInput input, Callback<Response> response);
and send the json object like this
TypedInput input = null;
try {
JSONObject obj = newJSONObject();
obj.put("KEY", "value");
input = newTypedByteArray("application/json", obj.toString().getBytes("UTF-8"));
} catch (Exception e) {
e.printStackTrace();
}
callApi(input, newCallback<Response>() {
@Overridepublicvoidsuccess(Response response, Response response2) {
}
@Overridepublicvoidfailure(RetrofitError error) {
}
});
not of relative importance i am using retrofit 1.9
Post a Comment for "How To Post Json Object Using Retrofit"