okhttp模拟表单(form)发送post请求

直接上代码

      //请求参数
        Page<Map<String, Object>> virtualDataEngine = fwDimService.findParentList("VIRTUAL_DATA_ENGINE", "", getPageable());
        if (virtualDataEngine.getSize() == 0) {
            throw new ResDsException("维度中未发现openLooKeng服务端地址,请检查.");
        }
        Map<String, Object> stringObjectMap = virtualDataEngine.getContent().get(0);
        String url = (String) stringObjectMap.get("dimValueCode");
        String extendInfo = byId.get().getExtendInfo();

        //创建连接
        OkHttpClient client = new OkHttpClient();
        //构建FormBody,传入参数
        MultipartBody formBody = new MultipartBody.Builder()
                .setType(MultipartBody.FORM)
                .addFormDataPart("catalogInformation", extendInfo)
                .build();
        //构建Request,将FormBody作为Post方法的参数传入
        final Request request = new Request.Builder()
                .url(url)
                .addHeader("X-Presto-User", "55")
                .post(formBody)
                .build();
        //将Request封装为Call
        Call call = client.newCall(request);
        //调用请求,重写回调方法
        Response response = call.execute();

你可能感兴趣的:(okhttp)