| 26 | private final OkHttpClient client = new OkHttpClient(); |
| 27 | |
| 28 | public void run() throws Exception { |
| 29 | RequestBody formBody = new FormBody.Builder() |
| 30 | .add("search", "Jurassic Park") |
| 31 | .build(); |
| 32 | Request request = new Request.Builder() |
| 33 | .url("https://en.wikipedia.org/w/index.php") |
| 34 | .post(formBody) |
| 35 | .build(); |
| 36 | |
| 37 | try (Response response = client.newCall(request).execute()) { |
| 38 | if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); |
| 39 | |
| 40 | System.out.println(response.body().string()); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | public static void main(String... args) throws Exception { |
| 45 | new PostForm().run(); |