美文网首页
OkHttp使用DELETE请求

OkHttp使用DELETE请求

作者: 穷格万物 | 来源:发表于2018-01-09 15:47 被阅读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 );
                }
            });
    
        }
    

    相关文章

      网友评论

          本文标题:OkHttp使用DELETE请求

          本文链接:https://www.haomeiwen.com/subject/xmfgnxtx.html