首页 > 解决方案 > 在改造 post 方法中为我的 MVC url 获取 404 错误

问题描述

我正在为我的忘记密码屏幕调用改造后的方法,但我得到空响应,原因是 404 url​​ not found 错误请指导我,我是改造的初学者。

我的主要网址是这样的:

http://10.25.1.180:98/webapi/ForgtPassword

I am setting url like this

基本网址声明

public static String BASE_URL = "http://10.25.1.180:98/";

界面

public interface APIService {
    @FormUrlEncoded
    @POST("/webapi/ForgtPassword")
    Call<LoginModel> updateUser(@Field("username") String first, @Field("Device") String device);
}

主要活动.java

TextView responseText;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        responseText = (TextView) findViewById(R.id.responseText);
        APIInterface apiInterface = APIClient.getClient().create(APIInterface.class);




        /**
         Create new user
         **/

        LoginModel loginModel = new LoginModel("viren.r","A");
        Call<LoginModel> call1 = apiInterface.createUser(loginModel);
        call1.enqueue(new Callback<LoginModel>() {
            @Override
            public void onResponse(Call<LoginModel> call, Response<LoginModel> response) {
                LoginModel user1 = response.body();
                Log.e("Response is====",response.toString());

                if (response.isSuccessful())
                    Log.e("Success", new Gson().toJson(response.body()));
                else

                    Log.e("unSuccess", new Gson().toJson(response.errorBody()));


            }

            @Override
            public void onFailure(Call<LoginModel> call, Throwable t) {
                Toast.makeText(getApplicationContext(), "Fail=====", Toast.LENGTH_SHORT).show();


            }


        });

        /**
         GET List Users
         **/
//        Call<UserList> call2 = apiInterface.doGetUserList("2");
//        call2.enqueue(new Callback<UserList>() {
//            @Override
//            public void onResponse(Call<UserList> call, Response<UserList> response) {
//
//                UserList userList = response.body();
//                Integer text = userList.page;
//                Integer total = userList.total;
//                Integer totalPages = userList.totalPages;
//                List<UserList.Datum> datumList = userList.data;
//                Toast.makeText(getApplicationContext(), text + " page\n" + total + " total\n" + totalPages + " totalPages\n", Toast.LENGTH_SHORT).show();
//
//                for (UserList.Datum datum : datumList) {
//                    Toast.makeText(getApplicationContext(), "id : " + datum.id + " name: " + datum.first_name + " " + datum.last_name + " avatar: " + datum.avatar, Toast.LENGTH_SHORT).show();
//                }
//
//
//            }
//
//            @Override
//            public void onFailure(Call<UserList> call, Throwable t) {
//                call.cancel();
//            }
//        });


        /**
         POST name and job Url encoded.
         **/
//        Call<UserList> call3 = apiInterface.doCreateUserWithField("morpheus","leader");
//        call3.enqueue(new Callback<UserList>() {
//            @Override
//            public void onResponse(Call<UserList> call, Response<UserList> response) {
//                UserList userList = response.body();
//                Integer text = userList.page;
//                Integer total = userList.total;
//                Integer totalPages = userList.totalPages;
//                List<UserList.Datum> datumList = userList.data;
//                Toast.makeText(getApplicationContext(), text + " page\n" + total + " total\n" + totalPages + " totalPages\n", Toast.LENGTH_SHORT).show();
//
//                for (UserList.Datum datum : datumList) {
//                    Toast.makeText(getApplicationContext(), "id : " + datum.id + " name: " + datum.first_name + " " + datum.last_name + " avatar: " + datum.avatar, Toast.LENGTH_SHORT).show();
//                }
//
//            }
//
//            @Override
//            public void onFailure(Call<UserList> call, Throwable t) {
//                call.cancel();
//            }
//        });

    }
}

我正在使用 Apiclient 类从主要活动中调用改造库

public class APIClient {

    private static Retrofit retrofit = null;

    public static Retrofit getClient() {

        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();


        retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .client(client)
                .build();



        return retrofit;
    }

}

我如何解决这个错误。请指导我设置 url 是设置 mvc url 所需的任何扩展名,如 php.In php url 以 .php 扩展名结尾,在 mvc 中需要这样的任何东西吗?

为什么我的 webapi url 出现此错误?我的代码中是否缺少任何内容。

标签: android

解决方案


推荐阅读