1. get 방식
OkHttpClient client = new OkHttpClient(); String run(String url) throws IOException { Request request = new Request.Builder() .url(url) .build(); Response response = client.newCall(request).execute(); return response.body().string(); }2. post 방식
public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); OkHttpClient client = new OkHttpClient(); JSONObject json = new JSONObject(); json.put("test", "1111"); json.put("test2", "2222"); RequestBody body = RequestBody.create(JSON, json.toString()); Request request = new Request.Builder() .url(url) .post(body) .build(); Response response = client.newCall(request).execute(); response.body().string();
'network' 카테고리의 다른 글
Uri.Builder 사용방법 (0) | 2015.02.11 |
---|---|
OkHttp 다운로드 (0) | 2015.02.11 |