| 98 | |
| 99 | |
| 100 | public static Response POST(String link, Map<String, String> headers, String body) throws IOException { |
| 101 | URL url = new URL(link); |
| 102 | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
| 103 | connection.setRequestMethod("POST"); |
| 104 | |
| 105 | for (Entry<String, String> entry : headers.entrySet()) { |
| 106 | connection.setRequestProperty(entry.getKey(), entry.getValue()); |
| 107 | } |
| 108 | |
| 109 | connection.setUseCaches(false); |
| 110 | |
| 111 | connection.setDoOutput(true); |
| 112 | |
| 113 | connection.connect(); |
| 114 | OutputStream os = connection.getOutputStream(); |
| 115 | os.write(body.getBytes(StandardCharsets.UTF_8)); |
| 116 | os.flush(); |
| 117 | os.close(); |
| 118 | |
| 119 | Response response = new Response(); |
| 120 | response.statusCode = connection.getResponseCode(); |
| 121 | response.headers = connection.getHeaderFields(); |
| 122 | response.body = connection.getInputStream().readAllBytes(); |
| 123 | |
| 124 | connection.getInputStream().close(); |
| 125 | |
| 126 | return response; |
| 127 | } |
| 128 | |
| 129 | |
| 130 | public static Response POST(String link, Map<String, String> headers, byte[] buffer, int pos, int size) throws IOException { |