Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. class web {
  2.     private final OkHttpClient client = new OkHttpClient();
  3.     private String html;
  4.  
  5.     public String get() {
  6.         System.out.println("Result html " + this.html); //Здесь выводит NULL
  7.         return this.html;
  8.     }
  9.  
  10.     public void set(String html) {
  11.         this.html = html;
  12.     }
  13.  
  14.     public void httpPost(final String url, final String param) {
  15.  
  16.         FormBody.Builder formBuilder = new FormBody.Builder();
  17.         RequestBody formBody = formBuilder.build();
  18.         Request request = new Request.Builder()
  19.                 .url(url)
  20.                 .build();
  21.  
  22.         client.newCall(request).enqueue(new Callback() {
  23.             @Override
  24.             public void onFailure(Call call, IOException e) {
  25.  
  26.             }
  27.  
  28.             @Override
  29.             public void onResponse(Call call, final Response response) throws IOException {
  30.                 if (!response.isSuccessful()) {
  31.                     throw new IOException("Unexpected code " + response);
  32.                 } else {
  33.                     set(response.body().string());
  34.                 }
  35.             }
  36.  
  37.         });
  38.  
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement