liulingling.177216
2024-08-26 349f1cfc5fa77fbc636d542df0d8050fddec48c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.dingzhuo.energy.project.conglomeratepush;
 
import okhttp3.*;
 
import java.io.IOException;
import java.util.Map;
 
/**
 *OkHttpClient 发送
 *
 * @author zhw
 * @since 2022-03-09
 */
public class HttpUtil {
 
 
    /**
     * post请求
     * @param params
     * @param url
     * @return
     */
    public static Response post(Map<String,String> params, String url){
 
        OkHttpClient client = new OkHttpClient();
        FormBody.Builder builder = new FormBody.Builder();
 
        for (Map.Entry<String, String> entry : params.entrySet()) {
            builder.add(entry.getKey(),entry.getValue());
        }
        RequestBody formBody = builder.build();
 
        Request request = new Request.Builder()
                .url(url)
                .post(formBody)
                .build();
 
        try {
            Response response = client.newCall(request).execute();
            return response;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
 
    /**
     *get请求
     * @param url
     * @return
     */
    public static Response get(String url){
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
            .url(url)
            .build();
        try {
            Response response = client.newCall(request).execute();
            return response;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
 
}