我正在使用 Retrofit 访问一个 RESTful API。基本 URL 为:
这是接口的代码:
public interface ExampleService {
@Headers("Accept: Application/JSON")
@POST("/album/featured-albums")
Call<List<Album>> listFeaturedAlbums();
}
这是我发送请求并接收响应的方式:
new AsyncTask<Void, Void, Response<List<Album>>>() {
@Override
protected Response<List<Album>> doInBackground(Void... params) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://api.example.com/service")
.addConverterFactory(GsonConverterFactory.create())
.build();
ExampleService service = retrofit.create(ExampleService.class);
try {
return service.listFeaturedAlbums().execute();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Response<List<Album>> listCall) {
Log.v("Example", listCall.raw().toString());
}
}.execute();
我得到的日志是奇怪的东西:
V/Example﹕ Response{protocol=http/1.1, code=404, message=Not Found, url=http://api.example.com/album/featured-albums}
这里发生了什么?