java.io.IOException: Server returned HTTP response code: 403 for URL

前端 未结 5 1137

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 f

5条回答
  •  隐瞒了意图╮
    2020-12-13 11:05

    You can also use

    System.setProperty("http.agent", "Chrome");
    

    it worked for me.

    //Update

    Explanation

    Because HttpURLConnection reads the property "http.agent" if set. You can read it here: https://www.innovation.ch/java/HTTPClient/advanced_info.html

    Or you can look it up in the source code of the HttpURLConnection Class:

    String agent = java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction("http.agent"));

提交回复
热议问题