Chinaunix首页 | 论坛 | 博客
  • 博客访问: 84205
  • 博文数量: 98
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 600
  • 用 户 组: 普通用户
  • 注册时间: 2014-06-10 21:50
文章分类
文章存档

2014年(98)

我的朋友

分类: Java

2014-07-18 14:33:39

1.   xsi:schemaLocation=" ">
  4.0.0
 
  com.yeetrack
  yinyueyun-download
  0.0.1-SNAPSHOT
  jar
 
  yinyueyun-download
 
 
 
    UTF-8
 

 
 
   
        org.apache.httpcomponents
        httpclient
        4.3.1
   

   
        com.alibaba
        fastjson
        1.1.37
   

 


2.package com.yeetrack.yinyueyun;
import java.util.List;
 * Created with IntelliJ IDEA.
 * User: victor
 * Date: 13-10-23
 * Time: 下午7:30
 * To change this template use File | Settings | File Templates.
public class DataEntity
    private List songList;
    public List getSongList()
        return songList;
    public void setSongList(List songList)
        this.songList = songList;
3.package com.yeetrack.yinyueyun;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.ProtocolException;
import org.apache.http.client.CookieStore;
import org.apache.http.client.RedirectStrategy;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.http.protocol.HttpContext;
 * @author victor 
public class HttpTool 
    private static CloseableHttpClient httpClient;
    private static String cookieName = "BDUSS";
    private static String cookieValue = "
    public static CloseableHttpClient getHttpClient()
            CookieStore cookieStore = new BasicCookieStore();
            BasicClientCookie baiduCookie = new BasicClientCookie(cookieName, cookieValue);
            baiduCookie.setDomain(".baidu.com");
            baiduCookie.setPath("/");
            cookieStore.addCookie(baiduCookie);       
            httpClient = HttpClients.custom()
                    .setDefaultCookieStore(cookieStore)
                    .setRedirectStrategy(new RedirectStrategy()
                        @Override
                        public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException
                            return false;  //To change body of implemented methods use File | Settings | File Templates.
                     @Override
                        public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException
                        {                            return null;  //To change body of implemented methods use File | Settings | File Templates.
                    .build();
        return httpClient;

阅读(322) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~