Skip to content

Instantly share code, notes, and snippets.

@a1yama
Created January 28, 2016 04:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a1yama/37f15f69de01b2840e9f to your computer and use it in GitHub Desktop.
Save a1yama/37f15f69de01b2840e9f to your computer and use it in GitHub Desktop.
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