日期:2014-05-17 浏览次数:20672 次
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
public class T1 {
public static void main(String[] args) throws UnsupportedEncodingException, Throwable {
String downloadUrl = "http://zhangmenshiting.baidu.com/data2/music/91731224/91731224.mp3?xcode=35364211a9bc8d289ad59150fa1ad1eb5dc4eabdf6e0aebb";
URL url = new URL(downloadUrl);
// 打开HttpURLConnection
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// 设置 HttpURLConnection的断开时间
conn.setConnectTimeout(5000);
// 设置 HttpURLConnection的请求方式
conn.setRequestMethod("GET");
// 设置 HttpURLConnection的接收的文件类型
conn.setRequestProperty(
"Accept",
"image/gif, image/jpeg, image/pjpeg, image/pjpeg, "
+ "application/x-shockwave-flash, application/xaml+xml, "
+ "application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, "
+ "application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
// 设置 HttpURLConnection的接收语音
conn.setRequestProperty("Accept-Language", Locale.getDefault().toString());
// 指定请求uri的源资源地址
conn.setRequestProperty("Referer", downloadUrl);
// 设置