Created
January 28, 2016 04:24
-
-
Save a1yama/37f15f69de01b2840e9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String result = null; | |
RequestBody body = new FormEncodingBuilder() | |
.addEncoded("key1", "value1") | |
.addEncoded("key2", "value2") | |
.addEncoded("key3", "value3") | |
.build(); | |
// リクエストオブジェクトを作って | |
Request request = new Request.Builder() | |
.url(base_url) | |
.header("Authorization", credential) | |
.post(body) | |
.build(); | |
// クライアントオブジェクトを作って | |
OkHttpClient client = new OkHttpClient(); | |
// リクエストして結果を受け取って | |
try { | |
Response response = client.newCall(request).execute(); | |
if (response.isSuccessful()){ | |
result = response.body().string(); | |
Log.d("hoge", "doPost success"); | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
Log.e("hoge", "error orz:" + e.getMessage(), e); | |
} | |
// 返す | |
return result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment