我正在学习改造。我已经完成了使用改造的一个login类(通过遵循Internet上的教程)。

现在,我尝试创建其他进程,即sign up。我很困惑应该在login函数中更改哪一个。老实说,我无法理解这些概念。

这是我的几个login的代码:

UserLogin.java

public class UserLog {

    private String id;
    private String username;
    private String password;
//getter and setter...


RestCallBack.java

public abstract class RestCallBack<T> implements Callback<T> {

    public abstract void failure(RestError restError);

    @Override
    public void failure (RetrofitError error){
        RestError restError = (RestError) error.getBodyAs(RestError.class);// create your own class as
        // how the error message gonna showup from server side if there is an error

        if(restError != null){
            failure(restError);
        }else{
            failure(new RestError(error.getMessage()));
        }
    }
}


RestError.java

public class RestError  {

    public Integer errorCode;
    public String extendedMessage;
    private String message;
    private String moreInfo;
    private Integer status;

//getter and setter


SessionRequest.java

public class SessionRequestInterceptor implements RequestInterceptor {

    private static final String TAG = SessionRequestInterceptor.class.getSimpleName();

    @Override
    public void intercept(RequestFacade request) {
        request.addHeader("Content-Type", "application/json");/*
        you can add header here if you need in your api
        */
    }
}


RestLoginCLient.java

public class RestClient_Login {

    private static RestApi_login REST_CLIENT;
    private static String ROOT = "http://192.168.10/testapp";


    static {
        setUpRestClient();
    }


    public static RestApi_login get()
    {return REST_CLIENT;}

    private static void setUpRestClient(){
        RestAdapter restAdapter = new RestAdapter.Builder()
                .setLogLevel(RestAdapter.LogLevel.FULL)
                .setEndpoint(ROOT)
                .setClient(new OkClient(new OkHttpClient()))
                .setRequestInterceptor(new SessionRequestInterceptor())
                .build();

        REST_CLIENT = restAdapter.create(RestApi_login.class);
    }


RestApi.java

public interface RestApi_login {
            @POST("/user/login")
            void login(@Body UserLog user,
                       RestCallBack<LoginResponse> callBack);
}


LoginResponse.java

public class LoginResponse {
    public String email;
    public String id;
    public String error;
    public UserLog resp;

    LoginResponse(){}

//getter and setter


指导我应该更改哪个代码才能创建我的sign up流程

最佳答案

对于登录,您可以点击this链接。这可以逐步说明代码中也发生了什么。这样您也可以了解自己在做什么。

关于android - 改造:使用改造将数据发送到服务器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33096951/

10-12 04:15