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

前端 未结 5 1133

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 10:52

    When I access the URL with my browser I also get 403. Perhaps you're logged in to the site with your browser?

    If that's the case you need to duplicate the cookie from your browser and send it along, perhaps even do more to replicate your browser's signature if the site does any extra checks.

    You can set the cookie by adding:

    urlConn.setRequestProperty("Cookie", "foo=bar"); 
    

    Where foo=bar is the key-value pair you'll find when you locate the site's cookie in your browser.

提交回复
热议问题