package com.cftech.pay.weixin.kit;

import okhttp3.*;

import java.io.IOException;

/**
 * Created by user on 2017/5/11.
 */
public class HttpUtilKit {

    private static OkHttpClient client = new OkHttpClient();
    public static final MediaType JSON
            = MediaType.parse("application/xml; charset=utf-8");

    public static String doPost(String url,String xml) throws IOException
    {
        RequestBody body = RequestBody.create(JSON, xml);
        Request request = new Request.Builder().url(url).post(body).build();
        Response response = client.newCall(request).execute();
        if (response.isSuccessful())
        {
            return response.body().string();
        } else {
            throw new IOException("Unexpected code " + response);
        }
    }

    public static String doGet(String url) throws IOException
    {
        Request request = new Request.Builder().url(url).build();
        Response response = client.newCall(request).execute();
        if (response.isSuccessful())
        {
            return response.body().string();
        } else {
            throw new IOException("Unexpected code " + response);
        }
    }

}
