java - How to load images from URL in JavaFx if recieving HTTP Error 403 -
i trying out thought duplicate , simple question, turned out more complicated , couldn't give definite answer. here original question.
i tried code different images on sites using https protocol , none worked. took images , added them sites use http protocol , worked.
so, questions how load image in imageview if site hosting image using https protocol?
it’s not https issue. seems cdn.discordapp.com requires user-agent
header in http request. furthermore, site appears accept formats user-agent. turns out user-agent supplied wget accepted:
image createimage(string url) throws ioexception { urlconnection conn = new url(url).openconnection(); conn.setrequestproperty("user-agent", "wget/1.13.4 (linux-gnu)"); try (inputstream stream = conn.getinputstream()) { return new image(stream); } }
without user-agent header in request, site gives http 403 forbidden response.
Comments
Post a Comment