이미지 URL이 실제 이미지를 가리키는지 확인합니다. 문제를 일으키는 URL의 공백 (Check if an image URL points to an actual image. Space in URL in causing issue)


문제 설명

이미지 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:

  1. Check that the HTTP.responseCode is a 1XX or a 2XX code. If not, the URL isn't an (accessible) image
  2. Try checking the response header: content‑type

(by Deepak P KumarAngellic DollControlAltDel)

참조 문서

  1. Check if an image URL points to an actual image. Space in URL in causing issue (CC BY‑SA 2.5/3.0/4.0)

#image #url-validation #java






관련 질문

이미지가 추가될 때 div 높이가 과도하게 늘어남 (div height overstretching when image is appended)

MS-Outlook 임베디드 이미지를 가져오고 MS-Access VBA를 사용하여 파일 시스템에 저장 (Getting MS-Outlook embedded images and saving them within the file system using MS-Access VBA)

Android 이미지 갤러리 이미지 자르기 및 ImageView 설정 (Android Image Gallery Crop Image and set ImageView)

Facebook은 드래그하여 이미지를 닫는 데 어떤 라이브러리를 사용합니까? (What library does Facebook use for dismiss image by dragging?)

이미지를 Picturebox(VB6의 이미지)에서 문자열(Base64)로 변환하는 방법은 무엇입니까? (How to convert Image from a Picturebox(Image in VB6) to String(Base64)?)

HTML, Canvas 및 WebGL 간의 품질 차이 (Quality differences between HTML, Canvas and WebGL)

TBitmapImage는 Inno Setup 6에서 크기 조정된 디스플레이의 크기보다 크게 렌더링됩니다. (TBitmapImage is rendered larger than its size on scaled display in Inno Setup 6)

이미지 URL이 실제 이미지를 가리키는지 확인합니다. 문제를 일으키는 URL의 공백 (Check if an image URL points to an actual image. Space in URL in causing issue)

android studio에서 인텐트를 통해 여러 콘텐츠를 보내는 방법 (how can i send multiple contents through intent in android studio)

Squarespace 사이트용 CSS로 이미지의 위치를 완벽하게 제어 (Fully Control The Location of an Image with CSS for Squarespace site)

iText7을 사용하여 PDFButtonFormField에 이미지를 추가할 때 종횡비를 유지하는 방법 (How to Maintain Aspect Ratio when Adding an Image to a PDFButtonFormField using iText7)

png 이미지에서 픽셀 색상 추출 (extracting pixel color from png image)







코멘트