java.io.IOException: Server returned HTTP response code: 403 for URL
Posted
by
Adao
on Stack Overflow
See other posts from Stack Overflow
or by Adao
Published on 2010-10-06T03:45:42Z
Indexed on
2011/03/05
7:24 UTC
Read the original article
Hit count: 327
I want to download the mp3 file from url : "http://upload13.music.qzone.soso.com/30671794.mp3", i always got java.io.IOException: Server returned HTTP response code: 403 for URL. But it's ok when open the url using browser. Below is part of my code:
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()));?
Anyone could help me? Thanks in advance!
© Stack Overflow or respective owner