Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class web {
- private final OkHttpClient client = new OkHttpClient();
- private String html;
- public String get() {
- System.out.println("Result html " + this.html); //Здесь выводит NULL
- return this.html;
- }
- public void set(String html) {
- this.html = html;
- }
- public void httpPost(final String url, final String param) {
- FormBody.Builder formBuilder = new FormBody.Builder();
- RequestBody formBody = formBuilder.build();
- Request request = new Request.Builder()
- .url(url)
- .build();
- 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 {
- if (!response.isSuccessful()) {
- throw new IOException("Unexpected code " + response);
- } else {
- set(response.body().string());
- }
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement