httpclien模拟浏览器

Posted nidegui

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了httpclien模拟浏览器相关的知识,希望对你有一定的参考价值。

package com.java.httpclient;

import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
/**
 * HttpClient设置请求头消息User-Agent模拟浏览器 setheader key value来设置
 * @author nidegui
 *
 */
public class Helloword3 {
	public static void main(String[] args) throws IOException {
		CloseableHttpClient  httpclient=HttpClients.createDefault(); //创建浏览器实列
		HttpGet httpget=new HttpGet("http://www.tuicool.com"); //创建get实列
		httpget.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0");
		CloseableHttpResponse response=null;
		response=httpclient.execute(httpget);
        HttpEntity entity=response.getEntity();
		System.out.println("输出实体:"+EntityUtils.toString(entity,"utf-8"));
		response.close();
		httpclient.close();
	}
}

  

以上是关于httpclien模拟浏览器的主要内容,如果未能解决你的问题,请参考以下文章

cnzz 模拟请求登录(传入url get data ) demo

谷歌浏览器调试jsp 引入代码片段,如何调试代码片段中的js

HttpClien高并发请求连接池 - PoolingHttpClientConnectionManager

如何在C#中模拟基类属性或方法

web代码片段

十条实用的jQuery代码片段