package com.tc.musicplay.utils;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
/**
*
* @ClassName: HttpUtil
* @Description: Http工具类,发送Http请求, Get请求请将参数放在url中 Post请求请将参数放在Map中
* @author Simple
* @date 2017-5-16 上午9:56:45
*
*/
public class HttpUtil {
private static final Log log =LogFactory.getLog(HttpUtil.class);
private static final CloseableHttpClient httpclient = HttpClients.createDefault();
private static final String userAgent = "Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.87 Safari/537.36";
/**
* 发送HttpGet请求
*
* @param url
* 请求地址
* @return 返回字符串
*/
public static String sendGet(String url) {
String result = null;
CloseableHttpResponse response = null;
try {
HttpGet httpGet = new HttpGet(url);
httpGet.setHeader("User-Agent", userAgent);
response = httpclient.execute(httpGet);
HttpEntity entity = response.getEntity();
if (entity != null) {
result = EntityUtils.toString(entity,"GB2312");
}
} catch (Exception e) {
log.error("处理失败 {}" + e);
e.printStackTrace();
} finally {
if (response != null) {
try {
response.close();
} catch (IOException e) {
log.error(e.getMessage());
}
}
}
return result;
}
//
public static byte[] download(String url) {
byte[] result = null;
CloseableHttpResponse response = null;
try {
HttpGet httpGet = new HttpGet(url);
httpGet.setHeader("User-Agent", userAgent);
response = httpclient.execute(httpGet);
HttpEntity entity = response.getEntity();
if (entity != null) {
result = EntityUtils.toByteArray(entity);
}
} catch (Exception e) {
log.error("处理失败 {}" + e);
e.printStackTrace();
} finally {
if (response != null) {
try {
response.close();
} catch (IOException e) {
log.error(e.getMessage());
}
}
}
return result;
}
/**
* 发送HttpPost请求,参数为map
*
* @param url
* 请求地址
* @param map
* 请求参数
* @return 返回字符串
*/
public static String sendPost(String url, Map<String, String> map) {
// 设置参数
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
for (Map.Entry<String, String> entry : map.entrySet()) {
formparams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
// 编码
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(formparams, Consts.UTF_8);
// 取得HttpPost对象
HttpPost httpPost = new HttpPost(url);
// 防止被当成攻击添加的
httpPost.setHeader("User-Agent", userAgent);
// 参数放入Entity
httpPost.setEntity(formEntity);
CloseableHttpResponse response = null;
String result = null;
try {
// 执行post请求
response = httpclient.execute(httpPost);
// 得到entity
HttpEntity entity = response.getEntity();
// 得到字符串
result = EntityUtils.toString(entity);
} catch (IOException e) {
log.error(e.getMessage());
} finally {
if (response != null) {
try {
response.close();
} catch (IOException e) {
log.error(e.getMessage());
}
}
}
return result;
}
/**
* 发送HttpPost请求,参数为文件,适用于微信上传素材
*
* @param url
* 请求地址
* @param file
* 上传的文件
* @return 返回字符串
* @throws IOException
* @throws ClientProtocolException
*/
public static String sendPost(String url, File file) {
String result = null;
HttpPost httpPost = new HttpPost(url);
// 防止被当成攻击添加的
httpPost.setHeader("User-Agent", userAgent);
MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartEntity.addPart("media", new FileBody(file));
httpPost.setEntity(multipartEntity.build());
CloseableHttpResponse response = null;
try {
response = httpclient.execute(httpPost);
HttpEntity entity = response.getEntity();
result = EntityUtils.toString(entity);
} catch (IOException e) {
log.error(e.getMessage());
} finally {
// 关闭CloseableHttpResponse
if (response != null) {
try {
response.close();
} catch (IOException e) {
log.error(e.getMessage());
}
}
}
return result;
}
/**
* 发送HttpPost请求,参数为json字符串
*
* @param url
* @param jsonStr
* @return
*/
public static String sendPost(String url, String jsonStr) {
String result = null;
// 字符串编码
StringEntity entity = new StringEntity(jsonStr, Consts.UTF_8);
// 设置content-type
entity.setContentType("application/json");
HttpPost httpPost = new HttpPost(url);
// 防止被当成攻击添加的
httpPost.setHeader("User-Agent", userAgent);
httpPost.setEntity(entity);
CloseableHttpResponse response = null;
try {
response = httpclient.execute(httpPost);
HttpEntity httpEntity = response.getEntity();
result = EntityUtils.toString(httpEntity);
} catch (IOException e) {
log.error(e.getMessage());
} finally {
// 关闭CloseableHttpResponse
if (response != null) {
try {
response.close();
} catch (IOException e) {
log.error(e.getMessage());
}
}
}
return result;
}
/**
* 发送不带参数的HttpPost请求
*
* @param url
* @return
*/
public static String sendPost
没有合适的资源?快使用搜索试试~ 我知道了~
音乐播放器 音乐播放器
共96个文件
jar:32个
png:24个
class:6个
需积分: 16 18 下载量 184 浏览量
2017-06-14
14:39:10
上传
评论 2
收藏 12.05MB ZIP 举报
温馨提示
这是网页版的音乐播放器,实现了歌词同步显示,搜索音乐,音乐播放,循环的调整 这是网页版的音乐播放器,实现了歌词同步显示,搜索音乐,音乐播放,循环的调整 这是网页版的音乐播放器,实现了歌词同步显示,搜索音乐,音乐播放,循环的调整 这是网页版的音乐播放器,实现了歌词同步显示,搜索音乐,音乐播放,循环的调整 这是网页版的音乐播放器,实现了歌词同步显示,搜索音乐,音乐播放,循环的调整
资源推荐
资源详情
资源评论
收起资源包目录
MusicPlay.zip (96个子文件)
MusicPlay
config
springmvc
springmvc.xml 1KB
.settings
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.project.facet.core.xml 414B
org.eclipse.core.resources.prefs 79B
org.eclipse.wst.common.component 557B
org.eclipse.wst.jsdt.ui.superType.container 49B
.jsdtscope 522B
org.eclipse.jdt.core.prefs 364B
src
com
tc
musicplay
domain
MusicInfo.java 1KB
MusicLrc.java 491B
controller
MusicPlayController.java 2KB
utils
HttpUtil.java 9KB
MusicUtil.java 7KB
SongInfo.java 439B
.project 1KB
WebRoot
caches
artists
dengziqi.jpg 8KB
music
loveyou.m4a 741KB
META-INF
MANIFEST.MF 39B
WEB-INF
web.xml 1KB
lib
jackson-mapper-asl-1.9.11.jar 762KB
spring-core-3.2.0.RELEASE.jar 843KB
showapi_sdk.jar 29KB
dom4j-1.6.1.jar 307KB
spring-context-support-3.2.0.RELEASE.jar 124KB
sitemesh-2.2.1.jar 130KB
spring-expression-3.2.0.RELEASE.jar 189KB
httpmime-4.5.jar 40KB
spring-web-3.2.0.RELEASE.jar 610KB
httpclient-4.5.jar 711KB
jackson-core-asl-1.9.11.jar 227KB
fluent-hc-4.5.jar 31KB
spring-context-3.2.0.RELEASE.jar 834KB
spring-jdbc-3.2.0.RELEASE.jar 392KB
spring-webmvc-3.2.0.RELEASE.jar 621KB
fastjson-1.2.2.jar 400KB
httpcore-4.4.1.jar 315KB
jna-4.1.0.jar 893KB
jna-platform-4.1.0.jar 1.4MB
httpclient-cache-4.5.jar 155KB
commons-codec-1.9.jar 258KB
jstl-1.2.jar 405KB
spring-aop-3.2.0.RELEASE.jar 327KB
spring-tx-3.2.0.RELEASE.jar 235KB
spring-orm-3.2.0.RELEASE.jar 383KB
commons-logging-1.2.jar 60KB
spring-beans-3.2.0.RELEASE.jar 591KB
spring-test-3.2.0.RELEASE.jar 441KB
commons-io-2.2.jar 170KB
spring-aspects-3.2.0.RELEASE.jar 68KB
httpclient-win-4.5.jar 17KB
jaxen-1.1-beta-7.jar 222KB
assets
css
tapplayer.css 10KB
font-awesome.min.css 21KB
images
loop.png 427B
volume-mute.png 615B
shuffle.png 1KB
spinner.png 1KB
paused.png 3KB
stop.png 2KB
backward.png 1KB
bars.png 969B
download.png 16KB
cog.png 339B
all.png 2KB
pause.png 2KB
default_album.png 357KB
volume-low.png 643B
line_gray.png 931B
volume-medium.png 915B
purty_wood.png 217KB
forward.png 1KB
dark_wood.png 132KB
play.png 2KB
played.png 3KB
plus.png 976B
gray.png 929B
fonts
fontawesome-webfont.eot 55KB
fontawesome-webfont.woff 64KB
FontAwesome.otf 84KB
fontawesome-webfont.svg 280KB
fontawesome-webfont.ttf 110KB
js
jquery-1.11.3.js 278KB
randomSort.js 761B
tapplayer.js 11KB
iscroll.js 49KB
backgrounds
default.png 348KB
login.jsp 806B
classes
springmvc
springmvc.xml 1KB
com
tc
musicplay
domain
MusicLrc.class 809B
MusicInfo.class 1KB
controller
MusicPlayController.class 4KB
utils
MusicUtil.class 8KB
HttpUtil.class 8KB
SongInfo.class 350B
index.jsp 4KB
.classpath 4KB
共 96 条
- 1
资源评论
隔壁王小二
- 粉丝: 19
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Python的PCA人脸识别算法的原理及实现代码详解+源码+详细代码解析+开发文档+数据(毕业设计&课程设计&项目开发)
- Decision tree20240105(1).ipynb
- zuoyezuoyezuoye
- zuoyezuoyezuoye
- 机械设计电机转子装配设备sw22非常好的设计图纸100%好用.zip
- 作业作业作业作业作业作业
- xdotool.c
- RLMD鲁棒性局部均值分解信号分量可视化(Matlab完整源码和数据)
- Screenshot_2024-04-26-17-17-26-36_9d26c6446fd7bb8e41d99b6262b17def.jpg
- 6.0版本超广角文件+教程使用MT管理器打-7.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功