Retrofit2返回null responseBody

时间:2017-05-16 19:41:24

标签: android retrofit2

http删除成功但ResponseBody始终为null。缺少什么?谢谢。 .................................................. ..............................

import okhttp3.OkHttpClient;
import okhttp3.ResponseBody;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.http.DELETE;
import retrofit2.http.Headers;
import retrofit2.http.Url;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public interface MyClass {
    @DELETE
    rx.Observable<ResponseBody> deletePost(@Url String url);
}

HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging);

String url = "http:/some/base/url?device_id="
                        + Settings.Secure.getString(getActivity().getContentResolver(), Settings.Secure.ANDROID_ID)

new Retrofit.Builder()
      .baseUrl("http:/some/base/url/")
      .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
      .client(httpClient.build())
      .build().create(MyClass.class).deletePost(url)
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<ResponseBody>()

    {
                @Override
                public void onCompleted() {
                }

                @Override
                public void onError(Throwable e) {
                    Toast.makeText(getContext(), e.toString(), Toast.LENGTH_LONG).show();
                }

                @Override
                public void onNext(final ResponseBody response) {
                    if (response != null) {
                        Toast.makeText(getContext(), response.toString(), Toast.LENGTH_LONG).show();
                    }
                }
            });

http删除成功但ResponseBody始终为null。缺少什么? THX。

0 个答案:

没有答案