OkHttp使用DELETE请求

2018-01-09  本文已影响0人  穷格万物
public void doDelete(){

        OkHttpClient mOkHttpClient = new OkHttpClient().newBuilder()
                .sslSocketFactory(OKHttpSafeUtils.getUnSafeSocketFactory(), OKHttpSafeUtils.UnSafeTrustManager)
                .hostnameVerifier(OKHttpSafeUtils.UnSafeHostnameVerifier)
                .build();

        FormBody formBody = new FormBody.Builder().build();
        Request.Builder builder = new Request.Builder().url(getRequestUrl()).delete(formBody);
        builder.addHeader("bshtoken", getToken());
        Request request = builder.build();

        Call call = mOkHttpClient.newCall(request);

        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Log.e(TAG, "失败onFailure: " +e.getMessage());
            }
            @Override
            public void onResponse(Call call, Response response) throws IOException {
                ResponseBody body = response.body();
                String s = body.toString();
                Log.e(TAG, "成功onResponse: "+s );
            }
        });

    }
上一篇下一篇

猜你喜欢

热点阅读