我正在使用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