Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String requestOkHttp(String url, String method, String json) throws IOException {
- RequestBody requestBody;
- requestBody = METHOD_POST.equals(method) || METHOD_PUT.equals(method) ?
- RequestBody.create(JSON, json == null ? "" : json) : null;
- okhttp3.Request.Builder requestBuilder = new okhttp3.Request.Builder()
- .url(url);
- requestBuilder.method(method, requestBody);
- OkHttpClient client = new OkHttpClient();
- Response response = client.newCall(requestBuilder.build()).execute();
- return response.body().string();
- }
Advertisement
Add Comment
Please, Sign In to add comment