使用Retrofit我遇到了奇怪的错误。在向其中一个端点发送请求后,我收到错误:
java.lang.IllegalArgumentException: RodoService.getRodoInfo: URL path "xxx.com" must start with '/'.
这很奇怪,因为其他终端工作。它也使用邮差,所以后端似乎没问题。
这是我的界面:
public interface RodoService {
String INFO_RODO = BASE_API_URL + "rodo/players/";
@GET(INFO_RODO)
void getRodoInfo(Callback<BaseResponse<RodoModel>> callback);
}
我的第二堂课:
public class RodoApi extends BaseApi {
private final RodoService service = restAdapter.create(RodoService.class);
public RodoApi() {
super();
}
public void getRodo(Callback<BaseResponse<RodoModel>> callback) {
service.getRodoInfo(callback);
}
}
在Activity中,我正在调用这样的API:
RodoApi rodoApi = new RodoApi();
rodoApi.getRodo(new Callback<BaseResponse<RodoModel>>() {
@Override
public void success(BaseResponse<RodoModel> rodoModelBaseResponse, Response response) {
Log.e("RESP", "success: " + response.getBody() );
}
@Override
public void failure(RetrofitError error) {
Log.e("RESP", "error: " + error.getMessage() );
}
});
你能帮帮我吗?正如我所说 - 其他endponts工作。谢谢!
答案 0 :(得分:0)
请检查以下代码。您连接BASE_URL + End Point并将其传递给@GET注释
Look @ Interface我写了
public interface RequestInterface {
@GET("recent")
Observable<MovieResponse> getRecentMovies();
}
RequestService类中的BASE URL实现
public class RequestService {
private static final String TAG = RequestService.class.getSimpleName();
public static final String BASEURL = "http://xxxxxxxxx.com/filmystanapi/public/api/v1/";
private RequestInterface requestInterface;
public RequestService() {
initRequestInterface();
}
private void initRequestInterface() {
requestInterface = new Retrofit.Builder()
.baseUrl(BASEURL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build()
.create(RequestInterface.class);
}
public Observable<MovieResponse> getRecentMovies() {
return requestInterface.getRecentMovies()
.retry(5)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.filter(movieResponse -> movieResponse.getStatus() == 200);
}
}
这可能与您的错误代码有关。