我正在为忘记密码的屏幕调用更新后的方法,但是我得到的响应为空,原因是未找到404 url错误,请指导我,这是我的新手。
我的主网址是这样:
http://10.25.1.180:98/webapi/ForgtPassword
I am setting url like this
基本URL声明:
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);
}
Mainactivity.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是设置像php这样的mvc url所需的任何扩展名。在以php扩展名结尾的php url中,在mvc中需要这样的扩展名吗?
为什么我的webapi url出现此错误?代码中是否缺少任何内容。