Android 改造 Api ID
Android Retrofit Api ID
您好,我在使用 retrovite 和 get 时遇到问题
我的 url 是这样的:
/infosRma?numRma=7978
我输入了我的 Api 界面:
@GET("/infosRma/{id}/numRma")
Call<Rma> getRma(@Path("id") int id);
和 activity
中的此 ID 号码
Call<Rma> rmaCall = apiInterface.getRma(79778);
rmaCall.enqueue(new Callback<Rma>() {
@Override
public void onResponse(Call<Rma> call, Response<Rma> response) {
Log.e(TAG, "onResponse*************: " + response.body() );
final Rma myResponse = response.body();
txtName.setText(myResponse.getName());
}
@Override
public void onFailure(Call<Rma> call, Throwable t) {
Log.e(TAG, "onFailure******************: " + t.getLocalizedMessage() );
}
});
但是无法连接
No address associated with hostname
你有什么想法吗
善良
您传递 ID 的方式,最终 URL 将是
baseUrl/infosRma/7978/numRma
这是不正确的。使用 Query
参数代替 Path
如下:
@GET("/infosRma/")
Call<Rma> getRma(@Query("numRma") int id);
您好,我在使用 retrovite 和 get 时遇到问题 我的 url 是这样的:
/infosRma?numRma=7978
我输入了我的 Api 界面:
@GET("/infosRma/{id}/numRma")
Call<Rma> getRma(@Path("id") int id);
和 activity
中的此 ID 号码Call<Rma> rmaCall = apiInterface.getRma(79778);
rmaCall.enqueue(new Callback<Rma>() {
@Override
public void onResponse(Call<Rma> call, Response<Rma> response) {
Log.e(TAG, "onResponse*************: " + response.body() );
final Rma myResponse = response.body();
txtName.setText(myResponse.getName());
}
@Override
public void onFailure(Call<Rma> call, Throwable t) {
Log.e(TAG, "onFailure******************: " + t.getLocalizedMessage() );
}
});
但是无法连接
No address associated with hostname
你有什么想法吗
善良
您传递 ID 的方式,最终 URL 将是
baseUrl/infosRma/7978/numRma
这是不正确的。使用 Query
参数代替 Path
如下:
@GET("/infosRma/")
Call<Rma> getRma(@Query("numRma") int id);