문제 설명
이미지 URL이 실제 이미지를 가리키는지 확인합니다. 문제를 일으키는 URL의 공백 (Check if an image URL points to an actual image. Space in URL in causing issue)
URL이 다음 코드로 실제 이미지를 가리키는지 확인하고 있습니다.
URL obj = new URL(imageUrl);
HttpURLConnection connection = (HttpURLConnection) obj.openConnection();
connection.setRequestMethod("GET");
int responseCode = connection.getResponseCode();
return (responseCode == HttpURLConnection.HTTP_OK) // success
하지만 이미지 URL에 공백이 있으면 이 함수는 URL이 유효한 동안 false를 반환합니다. 공간을 %20으로 변경하지 않습니다. 어떤 변경을 해야 하나요?
참조 솔루션
방법 1:
How about you replace spaces in imageUrl in regex with replaceAll() method?
방법 2:
Two parts to this:
- Check that the HTTP.responseCode is a 1XX or a 2XX code. If not, the URL isn't an (accessible) image
- Try checking the response header: content‑type
(by Deepak P Kumar、Angellic Doll、ControlAltDel)