mirror of
https://github.com/square/okhttp.git
synced 2025-11-24 18:41:06 +03:00
Rename com.squareup.okhttp to okhttp3
Maven group changes will come in follow up.
This commit is contained in:
49
samples/guide/src/main/java/okhttp3/recipes/PostFile.java
Normal file
49
samples/guide/src/main/java/okhttp3/recipes/PostFile.java
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Square, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package okhttp3.recipes;
|
||||
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class PostFile {
|
||||
public static final MediaType MEDIA_TYPE_MARKDOWN
|
||||
= MediaType.parse("text/x-markdown; charset=utf-8");
|
||||
|
||||
private final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
public void run() throws Exception {
|
||||
File file = new File("README.md");
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url("https://api.github.com/markdown/raw")
|
||||
.post(RequestBody.create(MEDIA_TYPE_MARKDOWN, file))
|
||||
.build();
|
||||
|
||||
Response response = client.newCall(request).execute();
|
||||
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
|
||||
|
||||
System.out.println(response.body().string());
|
||||
}
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
new PostFile().run();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user