| 30 | private final OkHttpClient client = new OkHttpClient(); |
| 31 | |
| 32 | public void run() throws Exception { |
| 33 | File file = new File("README.md"); |
| 34 | |
| 35 | Request request = new Request.Builder() |
| 36 | .url("https://api.github.com/markdown/raw") |
| 37 | .post(RequestBody.create(file, MEDIA_TYPE_MARKDOWN)) |
| 38 | .build(); |
| 39 | |
| 40 | try (Response response = client.newCall(request).execute()) { |
| 41 | if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); |
| 42 | |
| 43 | System.out.println(response.body().string()); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | public static void main(String... args) throws Exception { |
| 48 | new PostFile().run(); |