在rettofit

时间:2016-06-26 13:49:00

标签: android retrofit2 okhttp3

我正在使用Rettofite 2处理http服务,但我不知道为什么当我在改造中使用@query时,我不从服务器获取数据 这是我的代码

public class ServiceGenerator {
public static final String API_BASE_URL = "#########";

private static OkHttpClient.Builder httpClient = new OkHttpClient.Builder();

private static Retrofit.Builder builder =
        new Retrofit.Builder()
                .baseUrl(API_BASE_URL)
                .addConverterFactory(GsonConverterFactory.create());

public static <S> S createService(Class<S> serviceClass) {
    Retrofit retrofit = builder.client(httpClient.build()).build();
    return retrofit.create(serviceClass);
}

}

public interface IPageEndPoint {

@GET(PageParameter.GET_PAGE_BY_USER_ID_URI)
Call<PageDto> checkPageExist(@Query(PageParameter.USER_ID_4_GET_PAGE_BY_ID) String userId);
....


private void CheckPageExist(String loginId) {

    IPageEndPoint pageEndPoint = ServiceGenerator.createService(IPageEndPoint.class);
    retrofit2.Call<PageDto> call = pageEndPoint.checkPageExist(loginId);
    call.enqueue(new retrofit2.Callback<PageDto>() {
        @Override
        public void onResponse(retrofit2.Call<PageDto> call, retrofit2.Response<PageDto> response) {
            if (response.isSuccessful()) {
                PageDto pageDto = response.body();
                if (pageDto == null) {
                    publicMethods.putDateInShared(Constant.PageParameter.PAGE_ID, SharedParameter.NULL_SHARED_DATA);
                    Intent intent = new Intent(context, CreateProfileActivity.class);
                    intent.putExtra(Constant.CreateFragmentType.TYPE_KEY, Constant.CreateFragmentType.CREATE_PROFILE);
                    context.startActivity(intent);
                } else {
                    String pageId = pageDto.getId();
                    publicMethods.putDateInShared(Constant.PageParameter.PAGE_ID, pageId);
                    Intent intent = new Intent(context, MainLayoutWithDrawableActivity.class);
                    context.startActivity(intent);
                }

            } else {
                updateUi("response is not successful for check page exist");
            }
        }

        @Override
        public void onFailure(retrofit2.Call<PageDto> call, Throwable t) {
            updateUi("response failed");
        }
    });

}

我已多次查看我的代码,但我对这个问题感到困惑。

0 个答案:

没有答案