MCPcopy Create free account
hub / github.com/SEBV1/idlefish_monitor / postForm

Method postForm

src/main/java/com/github/utils/OkHttpUtil.java:13–40  ·  view source on GitHub ↗
(String url, Map<String, String> headers, Map<String, String> params)

Source from the content-addressed store, hash-verified

11
12 // POST请求,表单参数
13 public static String postForm(String url, Map<String, String> headers, Map<String, String> params) throws IOException {
14 FormBody.Builder formBuilder = new FormBody.Builder();
15 if (params != null && !params.isEmpty()) {
16 for (Map.Entry<String, String> entry : params.entrySet()) {
17 formBuilder.add(entry.getKey(), entry.getValue());
18 }
19 }
20 RequestBody body = formBuilder.build();
21
22 Request.Builder builder = new Request.Builder()
23 .url(url)
24 .post(body);
25
26 if (headers != null && !headers.isEmpty()) {
27 for (Map.Entry<String, String> entry : headers.entrySet()) {
28 builder.addHeader(entry.getKey(), entry.getValue());
29 }
30 }
31
32 Request request = builder.build();
33 try (Response response = client.newCall(request).execute()) {
34 if (!response.isSuccessful()) {
35 throw new IOException("Unexpected code " + response);
36 }
37 assert response.body() != null;
38 return response.body().string();
39 }
40 }
41
42 public static String postForm(String url, Map<String, String> headers, String data) throws IOException {
43

Callers 2

onApplicationEventMethod · 0.95
callMethod · 0.95

Calls 3

isEmptyMethod · 0.80
addMethod · 0.80
encodeMethod · 0.80

Tested by

no test coverage detected