我正在使用Retrofit2.0用于制作GET
请求我的REST URL。我不需要将任何参数传递给URL来提出请求。 怎么可以做出这种类型的请求?如何使用Retrofit2.0制作Java REST API GET请求?
这是我的代码,我做了什么!
接口::
public interface AllRolesAPI {
@GET("/SportsApp/allroles")
Call<AllRolesParams> getAllRoles();
}
类::: 我创造了用POJO库它包含了所有与setter和getter方法变量的类。
public void requestRoles() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(ENDPOINT)
.build();
AllRolesAPI allRolesParams = retrofit.create(AllRolesAPI.class);
Call<AllRolesParams> allRolesParamsCall = allRolesParams.getAllRoles();
allRolesParamsCall.enqueue(new Callback<AllRolesParams>() {
@Override
public void onResponse(Call<AllRolesParams> call, Response<AllRolesParams> response) {
//response.body().getErrDesc();
Log.v("SignupActivity", "Response :: " + response.body().getErrDesc());
}
@Override
public void onFailure(Call<AllRolesParams> call, Throwable t) {
Log.v("SignupActivity", "Failure :: ");
}
});
}
当我创建像上面我已经得到了在控制台::这个错误的请求
java.lang.IllegalArgumentException: Unable to create converter for class com.acknotech.kiran.navigationdrawer.AllRolesParams.
当我改变你说的代码...排队显示错误,就像找不到符号。 – Jaccs
是的,因为您需要将该依赖项添加到build.gradle文件中,并同步项目 –
否..仍然出错。 (); Retrofit retrofit = new Retrofit.Builder() .baseUrl(ENDPOINT) .addConverterFactory(GsonConverterFactory.create()) .build(); AllRolesAPI allRolesAPI = retrofit.create(AllRolesAPI.class); 调用 allrolesResponseCall = allRolesAPI.getAllRoles(); 这是什么代码现在我应该如何使得请求没有任何参数传递。 –
Jaccs