小编Ada*_*dao的帖子

java.io.IOException:服务器返回HTTP响应代码:403表示URL

我想从url下载mp3文件:"http://upload13.music.qzone.soso.com/30671794.mp3",我总是得到java.io.IOException:服务器返回HTTP响应代码:403为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()));?
Run Code Online (Sandbox Code Playgroud)

有人可以帮帮我吗?提前致谢!

java http http-status-code-403

20
推荐指数
3
解决办法
8万
查看次数

标签 统计

http ×1

http-status-code-403 ×1

java ×1