Header Ads

retofit post

Library : 
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.5.0'



Api.java
@FormUrlEncoded@POST("/service-change-password.php")
void ForgetPassword(@Field("password") String password, @Field("user_id") String user_id, Callback<ServicePasswordChangepojo>callback);

Method in activity:

private void ChangePasswordApi() {
    dialog.ShowProgressDialog();
    RestClient.get().ForgetPassword(pass, userid, new Callback<ServicePasswordChangepojo>() {
        @Override        public void success(ServicePasswordChangepojo searchPojo, Response response) {
            Toast.makeText(context, searchPojo.getStatus(), Toast.LENGTH_SHORT).show();
            System.out.println(password.getText().toString() + " success" + health_shared_pref.getPrefranceStringValue(Health_Api.USERID));
            dialog.CancelProgressDialog();
        }

        @Override        public void failure(RetrofitError error) {
            System.out.println(" faill");
            Toast.makeText(context, "Password not change!", Toast.LENGTH_SHORT).show();
            dialog.CancelProgressDialog();
        }
    });
}


RestClient Class:

public class RestClient {

    private static Api REST_CLIENT;
    private static String ROOT = "https://2040healthcare.com/app/";
    static {
        setupRestClient();
    }

    private RestClient() {
    }

    public static Api get() {
        return REST_CLIENT;
    }


    private static void setupRestClient() {
        RestAdapter.Builder builder = new RestAdapter.Builder()
                .setEndpoint(ROOT)
                .setClient(new OkClient(new OkHttpClient()));
        builder.setLogLevel(RestAdapter.LogLevel.FULL);

        RestAdapter restAdapter = builder.build();
        REST_CLIENT = restAdapter.create(Api.class);
    }
}

PojoClass:
public class ServicePasswordChangepojo {

    String status;
    String user_id;

    public String getUser_id() {
        return user_id;
    }

    public void setUser_id(String user_id) {
        this.user_id = user_id;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    String password;

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getResponse() {
        return response;
    }

    public void setResponse(String response) {
        this.response = response;
    }

    String response;

}

No comments

Powered by Blogger.