Skip to content Skip to sidebar Skip to footer

Android Retrofit Post Json Object

Hi i am new using Retrofit and i am stucked for posting an json to the server. Initially i only had fields params with no arraylist in it . But now i have a whole json obje

Solution 1:

use this instead of your InterFace ....

publicinterfaceRetroApiInterface {
    @POST("synkku/operations.php")   //removed backslash from url 
    void createNewSeekerProfile(
            @Body SeekerProfileModel body, Callback<SeekerProfileModel> callback);
}

and add these .addConverterFactory(GsonConverterFactory.create()) line in your RestAdapter .... like below ....

RestAdapteradapter=newRestAdapter.Builder()
                .addConverterFactory(GsonConverterFactory.create()) //these line is convert your POJO into JSON and Vice Versa 
                .setEndpoint(Allconstants.MAIN_URL) //Setting the Root URL
                .build();  

Note:- Always try to start Post Or Get url withput backslash and put backslash at end in your intial url eg(like this www.XXXx.XXXX/).

EDIT:- add these dependencies in your grade ....

add the

compile'com.squareup.retrofit2:converter-gson:2.0.0'compile'com.google.code.gson:gson:2.7' //this is same as Ravi told 

Above example for retrofit 2.0 and above liberalizes ....

For retrofit 1.9 your all url is fine and RestAdapter also good

check you onFaliure() method and post here if any exception there .........

Solution 2:

Finally solved the issue.. The post request using retrofit 1.9 with the above mentioned code was absolutely working fine just that i had missed another @query string along with body in retrofit interface and the problem was with the php encoding json which i solved using following line of code $data = json_decode(file_get_contents('php://input'), true); $fullname=$data['full_name'];

Thanks to all those who spent time trying to help me with this issue

Post a Comment for "Android Retrofit Post Json Object"