okhttp post请求添加参数

HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(new OkhttpLogger());
        httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .connectTimeout(10,TimeUnit.SECONDS)
                .addNetworkInterceptor(httpLoggingInterceptor)
                .readTimeout(10,TimeUnit.SECONDS)
                .build();

//        RequestBody headers = RequestBody.create(JSON);

        FormBody.Builder requestBody = new FormBody.Builder();
        requestBody.add("appproject","1");
        Map map = new HashMap<>();
        map.put("appproject","1");
        Request request = new Request.Builder()
                .post(RequestBody.create(JSON,new Gson().toJson(map)))
                .url(url)
                .build();

        Call call = okHttpClient.newCall(request);

你可能感兴趣的:(Android)