/*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/ package org.apache.http.examples.client; import org.apache.http.client.ResponseHandler;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient; /**
* This example demonstrates the use of the {@link ResponseHandler} to simplify
* the process of processing the HTTP response and releasing associated resources.
*/
public class ClientWithResponseHandler { public final static void main(String[] args) throws Exception { HttpClient httpclient = new DefaultHttpClient();
try {
HttpGet httpget = new HttpGet("http://www.google.com/"); System.out.println("executing request " + httpget.getURI()); // Create a response handler
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = httpclient.execute(httpget, responseHandler);
System.out.println("----------------------------------------");
System.out.println(responseBody);
System.out.println("----------------------------------------"); } finally {
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
}
} }

Apache HttpComponents 获取页面内容String方式的更多相关文章

  1. C#获取页面内容的几种方式

    常见的Web页面获取页面内容用 WebRequest 或者 HttpWebRequest 来操作 Http 请求. 例如,获取百度网站的 html 页面 var request = WebReques ...

  2. vue-learning:12-vue获取模板内容的方式

    vue获取模板内容的方式 目录 outerHTML获取内容 template属性获取内容 ES6的字符串模板 <template>标签 <srcipt type="text ...

  3. Js之Dom学习-三种获取页面元素的方式、事件、innerText和innerHTML的异同

    一.三种获取页面元素的方式: getElementById:通过id来获取 <body> <input type="text" value="请输入一个 ...

  4. PHP curl获取页面内容,不直接输出到页面,CURLOPT_RETURNTRANSFER参数设置

    使用PHP curl获取页面内容或提交数据,有时候希望返回的内容作为变量储存,而不是直接输出.这个时候就必需设置curl的或true. 1.curl获取页面内容, 直接输出例子: <?php $ ...

  5. PHP CURL获取页面内容输出例子

    使用PHP curl获取页面内容或提交数据,有时候希望返回的内容作为变量储存,而不是直接输出.这个时候就必需设置curl的CURLOPT_RETURNTRANSFER选项为1或true. 1.curl ...

  6. python+selenium 页面中存在选项卡时,获取页面内容的小技巧

    最近用selenium读取页面内容时,遇到包含选项卡的页面,由于选项卡多由js加载其中的内容,所以在网址打开时只能获取到默认显示的选项卡中的内容,而tab2.tab3等等都需要傻傻的点击一下才会获取到 ...

  7. 【apache tika】apache tika获取文件内容(与FileUtils的对比)

    Tika支持多种功能: 文档类型检测 内容提取 元数据提取 语言检测 重要特点: 统一解析器接口:Tika封装在一个单一的解析器接口的第三方解析器库.由于这个特征,用户逸出从选择合适的解析器库的负担, ...

  8. POST信息模拟登录获取页面内容

    最近项目里有一个是要模拟登录后,访问固定页面获取内容的要求,一开始用JQ AJAX好像不支持跨域请求.后使用.net中HttpWebRequest对象来获取.一开始访问总是无法在第二个页面正常访问,好 ...

  9. python 携带cookie获取页面内容

    有时会遇到爬取的页面需要登录,这就要带上cookie了. 下面记录了几种携带cookie的方法 # coding=utf-8 import requests s = requests.Session( ...

随机推荐

  1. php调试利器Xhprof的安装与使用

    一.安装xhprof wget http://pecl.php.net/get/xhprof-0.9.4.tgz tar -zxvf xhprof-0.9.4.tgz cd xhprof-0.9.4/ ...

  2. nyoj-----前缀式计算

    前缀式计算 时间限制:1000 ms  |           内存限制:65535 KB 难度:3   描述 先说明一下什么是中缀式: 如2+(3+4)*5这种我们最常见的式子就是中缀式. 而把中缀 ...

  3. GFW的前世今生,一部GFW之父方滨兴的发家史

    http://whu.myubbs.com/thread-96390-1-1.html方滨兴(1960年7月17日-),男,中国共chan党党员,中国工程院院士,全国人大代表,中国科学院信息工程研究所 ...

  4. NVIDIA PureVideo Decoder解码器注册码

    http://www.amznz.com/nvidia-purevideo-decoder/ 重装系统后当然得装终极解码来看高清电影,这次为了给喜欢看HD影片的朋友,特意奉上NVIDIA7以上显卡的N ...

  5. [android] 网络断开的监听

    标签: android 网络监听 杂谈 分类: Android [转自]  http://blog.sina.com.cn/s/blog_5d5996d001012o07.html 其实手机在网络方面 ...

  6. Python sqrt() 函数

    描述 sqrt() 方法返回数字x的平方根. 语法 以下是 sqrt() 方法的语法: import math math.sqrt( x ) 注意:sqrt()是不能直接访问的,需要导入 math 模 ...

  7. 工作中常用的mysql操作

    一.在一个数据库中定义的存储过程或者是函数在另一数据库的存储过程中引用 1.我首先在数据库player_db中构建了一个函数:p_exp_to_level BEGIN ; ; RETURN v_lev ...

  8. cocos2dx 3.x fullPathForFilename及isFileExist在ios/mac下与win32下行为不同

    一,fullPathForFilename 项目先开发了ios/mac版本,这两天想把win32工程也配好,但遇到了部分资源无法正确找到的问题. 进一步观察发现,对于那些找不到的资源路径,fullPa ...

  9. 【C语言】调整数组使奇数所有都位于偶数前面(改动)

    //调整数组使奇数全部都位于偶数前面. //输入一个整数数组.实现一个函数,来调整该数组中数字的顺序使得数组中全部的奇数位于数组的前半部分,全部偶数位于数组的后半部分 #include <std ...

  10. openstack_swift源代码分析——Swift单机部署

    本文对在单机部署swift 当中每个细节做具体的介绍,并对配置做对应的解释 PC物理机    Ubuntu-12.04-desktop-64位 Swift 版本号:1.13.1 Swift-clien ...