Obtain data from the specified server through httpclient

From , 3 Years ago, written in Java, viewed 224 times.
URL https://pastebin.vip/view/a0443c8c
  1. DefaultHttpClient httpClient = new DefaultHttpClient();
  2.             HttpGet method = new HttpGet([u]http://www.baidu.com/1.html[/u]”);
  3.             HttpResponse resp;
  4.             Reader reader = null;
  5.             try {
  6.                 // AllClientPNames.TIMEOUT
  7.                 HttpParams params = new BasicHttpParams();
  8.                 params.setIntParameter(AllClientPNames.CONNECTION_TIMEOUT, 10000);
  9.                 httpClient.setParams(params);
  10.                 resp = httpClient.execute(method);
  11.                 int status = resp.getStatusLine().getStatusCode();
  12.            if (status != HttpStatus.SC_OK) return false;
  13.                // HttpStatus.SC_OK;
  14.                 return true;
  15.             } catch (ClientProtocolException e) {
  16.                 // TODO Auto-generated catch block
  17.                 e.printStackTrace();
  18.             } catch (IOException e) {
  19.                 // TODO Auto-generated catch block
  20.                 e.printStackTrace();
  21.             } finally {
  22.                 if (reader != null) try {
  23.                     reader.close();
  24.                 } catch (IOException e) {
  25.                     // TODO Auto-generated catch block
  26.                     e.printStackTrace();
  27.                 }
  28.             }
  29. //java/5272

Reply to "Obtain data from the specified server through httpclient"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website