retrofit.retrofitError:找不到404

时间:2017-06-08 15:44:32

标签: android

我在执行代码时遇到404错误,这意味着代码正在执行失败方法。我究竟做错了什么?我在onClick方法中调用registerUser()方法。我究竟做错了什么?这是我的代码:

RestAPI.java

public interface RegisterAPI {
@FormUrlEncoded
@POST("/account/register")
   public void registerUser(
            @Field("name") String name,
            @Field("email") String email,
            @Field("passowrd") String password,
            Callback<Response> callback
    );
}

registerUser()方法:

public void registerUser() {
        RestAdapter adapter = new RestAdapter.Builder()
                .setEndpoint(ROOT_URL) //Setting the Root URL
                .build();


        RegisterAPI api = adapter.create(RegisterAPI.class);

        api.registerUser(

                //Passing the values by getting it from editTexts
                name.getText().toString(),
                email.getText().toString(),
                password.getText().toString(),

                new Callback<Response>() {
                    @Override
                    public void success(Response result, Response response) {
                        //On success we will read the server's output using bufferedreader
                        //Creating a bufferedreader object
                        BufferedReader reader = null;

                        //An string to store output from the server
                        String output = "";

                        try {
                            //Initializing buffered reader
                            reader = new BufferedReader(new InputStreamReader(result.getBody().in()));

                            //Reading the output in the string
                            output = reader.readLine();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        Log.v("userDetails"," "+name+""+email+" "+password);
                        //Displaying the output as a toast
                        Toast.makeText(getActivity(), "Registration Successful", Toast.LENGTH_LONG).show();
                    }

                    @Override
                    public void failure(RetrofitError error) {

                        //If any error occured displaying the error as toast
                        Toast.makeText(getActivity(), error.toString(), Toast.LENGTH_LONG).show();
                    }
                }
        );
    }

ROOT_URL是:

public static final String ROOT_URL = "http://192.168.0.135:8000/api/v1";

0 个答案:

没有答案