Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Sender extends AsyncTask<String, String, String> {
- private static final OkHttpClient client = new OkHttpClient();
- protected String doInBackground(String... params) {
- try {
- //FormBody.Builder formParam= new FormBody.Builder();
- //formParam.add("access_token", "токен");
- //formParam.add("v", "5.73");
- //formParam.add("user_ids", "1");
- //RequestBody formBody = formParam.build();
- JSONObject obj = new JSONObject();
- obj.put("access_token", "токен");
- obj.put("v", "5.73");
- obj.put("user_ids", "1");
- RequestBody jsonBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"),
- obj.toString());
- Request request = new Request.Builder()
- .url("https://api.vk.com/method/"+params[0])
- .post(jsonBody )
- .build();
- Response response = client.newCall(request).execute();
- return response.body().string();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return "fail";
- }
- }
- Sender handler = new Sender();
- result = handler.execute("users.get").get();
Add Comment
Please, Sign In to add comment