package {{basePackage}}.utils.http;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.Method;
import sun.invoke.empty.Empty;

/**
 *
 */
public class HttpUtils {

    /**
     * dcrenl: 2023-09-08 8:51:55
     * Http请求
     * @param strUrl  请求的URL
     * @param method  请求方式
     * @param strBody
     * @return
     */
    public static HttpResponse getRequest(String strUrl, HttpMethod method, String strBody) {
        HttpRequest request = new HttpRequest(strUrl);
        HttpResponse response;

        //request.setUrl(strUrl);
        request.setMethod(Method.valueOf(method.name()));
        request.body(strBody);

        response = request.execute();

        return response;
    }

    /**
     * dcrenl: 2023-09-08 9:17:27
     * Http get请求
     * @param strUrl
     * @return
     */
    public static String httpGet(String strUrl) {

        return getRequest(strUrl, HttpMethod.GET, "").body();
    }

    /**
     * dcrenl: 2023-09-08 9:17:43
     * Http post请求
     * @param strUrl
     * @param strBody
     * @return
     */
    public static String httpPost(String strUrl, String strBody) {

        return getRequest(strUrl, HttpMethod.POST, strBody).body();
    }
}
