All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.fangxinqian.operator.sdk.utils.OkHttp Maven / Gradle / Ivy

There is a newer version: 1.1.2
Show newest version
package cn.fangxinqian.operator.sdk.utils;

import okhttp3.*;

import java.io.IOException;

/**
 * @Author NieZhiLiang
 * @Email [email protected]
 * @GitHub https://github.com/niezhiliang
 * @Date 2019-10-09 9:11 上午
 */
public class OkHttp {

    /**
     * 使用okhttp请求
     * @param url 请求地址
     * @param json 请求的json数据
     * @return
     * @throws IOException
     */
    public static String doPost(String url, String json) throws IOException {
        OkHttpClient client = new OkHttpClient();

        RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"),json);
        Request request = new Request.Builder()
                .url(url)
                .post(body)
                .build();
        try (Response response = client.newCall(request).execute()) {
            return response.body().string();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy