Reputation: 43
Now before you say there are questions like this I'd like to point out I've looked over most of them without any luck. Also I'm a first timer here so be gentle.
I have this annoyance right now in my current program:
Basically this part of my program uses a search engine to find torrent files.
public static ArrayList<String> search(String args) throws IOException {
args = args.replace(":", "");
ArrayList<String> list = new ArrayList<String>();
URL url = new URL("http://pirateproxy.net/search/" + args + "/");
URLConnection con = url.openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream())); <---- THIS
}
public static void main(String[] args) {
try {
search("The Hobbit: The Desolation of Smaug");
} catch (IOException e) {
e.printStackTrace();
}
}
THE ERROR:
java.io.IOException: Invalid Http response
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at service.ServiceDownloader.search(ServiceDownloader.java:20)
at service.ServiceDownloader.main(ServiceDownloader.java:45)
Now the fun part is that it ONLY goes wrong for this movie ("The Hobbit: The Desolation of Smaug"), every other movie works perfectly. I don't understand this. Please do help. (Also I have removed every unnecessary code from the search method)
If I did not put enough information here please ask me for more.
Upvotes: 4
Views: 16536
Reputation: 9839
Instead of concatenating strings and needlessly creating interim strings and failing because the url is not encoded, you can use the built in UriBuilder
to generate a valid URL
URL path = UriBuilder.fromPath("http://pirateproxy.net")
.path("search")
.path("some movie ")
.build()
.toURL();
// http://pirateproxy.net/search/some%20movie%20
Upvotes: 0
Reputation: 105
I suspect it tripped on the colon (:) not the space. Are there other titles with a colon?
Upvotes: 1
Reputation: 32468
You should URL encode the String The Hobbit: The Desolation of Smaug
, since you have special character there. Ex : space.
Upvotes: 4