I am checking if a URL points to an actual image with the following code:
URL obj = new URL(imageUrl);
HttpURLConnection connection = (HttpURLConnection) obj.openConnection();
connection.setRequestMethod("GET");
int responseCode = connection.getResponseCode();
return (responseCode == HttpURLConnection.HTTP_OK) // success
But if the image URL has a space in it, this function is returning false, while the URL is valid. It does not change space to %20. What changes should i make to it?
How about you replace spaces in imageUrl in regex with replaceAll() method?