okhttp postリクエストパラメータ追加

966 ワード

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);