我想从 url 下载 mp3 文件:“http://upload13.music.qzone.soso.com/30671794.mp3”,我总是得到 java.io.IOException: Server returned HTTP response code: 403 for URL。但是使用浏览器打开网址就可以了。以下是我的部分代码:
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
URL url = new URL(link);
URLConnection urlConn = url.openConnection();
urlConn.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
String contentType = urlConn.getContentType();
System.out.println("contentType:" + contentType);
InputStream is = urlConn.getInputStream();
bis = new BufferedInputStream(is, 4 * 1024);
bos = new BufferedOutputStream(new FileOutputStream(
fileName.toString()));
任何人都可以帮助我吗?提前致谢!