4

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.

2
  • What is the args value that you are passing at runtime? Did you manually checked opening the same URL that you are trying to access from your code Commented Mar 4, 2014 at 7:43
  • "pirateproxy.net/search/The Hobbit The Desolation of Smaug/" Which, if I copy paste into the address bar works fine. Commented Mar 4, 2014 at 8:41

3 Answers 3

4

You should URL encode the String The Hobbit: The Desolation of Smaug, since you have special character there. Ex : space.

Sign up to request clarification or add additional context in comments.

1 Comment

This works! But I still don't understand why. I've had several other movies with space in it that I didn't need to change for it to work.
1

I suspect it tripped on the colon (:) not the space. Are there other titles with a colon?

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.