java修改user-agent_HttpClient设置请求头消息User-Agent模拟浏览器

HttpClient设置请求头消息User-Agent模拟浏览器

用前面的代码:package com.open1111.httpclient.chap02;

import org.apache.http.HttpEntity;

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;

public class Demo01 {

public static void main(String[] args) throws Exception{

CloseableHttpClient httpClient=HttpClients.createDefault(); // 创建httpClient实例

HttpGet httpGet=new HttpGet("http://www.tuicool.com/"); // 创建httpget实例

CloseableHttpResponse response=httpClient.execute(httpGet); // 执行http get请求

HttpEntity entity=response.getEntity(); // 获取返回实体

System.out.println("网页内容:"+EntityUtils.toString(ent

你可能感兴趣的:(java修改user-agent_HttpClient设置请求头消息User-Agent模拟浏览器)