java.io.IOException:无效的Http响应

java.io.IOException:无效的Http响应,java,httpresponse,httpurlconnection,ioexception,Java,Httpresponse,Httpurlconnection,Ioexception,现在,在你说有这样的问题之前,我想指出,我已经看过了大部分问题,但没有任何运气。我也是第一次来这里,所以要温柔 在我目前的节目中,我有一个烦恼: 基本上,我程序的这一部分使用搜索引擎查找torrent文件 public static ArrayList<String> search(String args) throws IOException { args = args.replace(":", ""); ArrayList<String&g

现在,在你说有这样的问题之前,我想指出,我已经看过了大部分问题,但没有任何运气。我也是第一次来这里,所以要温柔

在我目前的节目中,我有一个烦恼:

基本上,我程序的这一部分使用搜索引擎查找torrent文件

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();
    }
}
有趣的是,这部电影(“霍比特人:斯马格的荒凉”)只出了问题,其他电影都是完美的。我不明白。请帮忙。(我还从搜索方法中删除了所有不必要的代码)


如果我没有在这里输入足够的信息,请向我索取更多信息。

你应该对字符串进行URL编码。
霍比特人:Smaug的荒凉
,因为你在那里有特殊的字符。例如:空格。

我怀疑它是在冒号(:)上绊倒的,而不是空格。是否还有其他带有冒号的标题?

您可以使用内置的来生成有效的url,而不是连接字符串和不必要地创建临时字符串,并且由于url未编码而失败

URL path = UriBuilder.fromPath("http://pirateproxy.net")
            .path("search")
            .path("some movie ")
            .build()
            .toURL();

// http://pirateproxy.net/search/some%20movie%20

运行时传递的args值是多少?您是否手动检查了打开您试图从代码“Hobbit the Saudison of Smaug/”中访问的同一URL,如果我将粘贴复制到地址栏中,该URL可以正常工作。这很有效!但我还是不明白为什么。我还拍过几部有空间的电影,我不需要改变它就可以工作。
URL path = UriBuilder.fromPath("http://pirateproxy.net")
            .path("search")
            .path("some movie ")
            .build()
            .toURL();

// http://pirateproxy.net/search/some%20movie%20