Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.io.IOException;
- import okhttp3.Call;
- import okhttp3.Callback;
- import okhttp3.MediaType;
- import okhttp3.OkHttpClient;
- import okhttp3.Request;
- import okhttp3.RequestBody;
- import okhttp3.Response;
- import okhttp3.MediaType;
- import okhttp3.OkHttpClient;
- public class Post {
- private static final MediaType JSON
- = MediaType.parse("application/json; charset=utf-8");
- OkHttpClient client = new OkHttpClient();
- public String post(String url, String json) throws IOException {
- RequestBody body = RequestBody.create(JSON, json);
- Request request = new Request.Builder()
- .url(url)
- .post(body)
- .build();
- Response response =client.newCall(request).enqueue(new Callback() {
- @Override
- public void onFailure(Call call, IOException e) {
- }
- @Override
- public void onResponse(Call call, final Response response) throws IOException {
- try {
- String responseData = response.body().string();
- JSONObject json = new JSONObject(responseData);
- final String owner = json.getString("name");
- } catch (JSONException e) {
- }
- }
- });
- return response.body().string();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement