java.io.IOException:服务器返回HTTP响应代码505 [英] java.io.IOException: Server returns HTTP response code 505
问题描述
我的代码中有基于HTML的查询,一个特定的类似乎在从服务器收到505响应时产生 IOExceptions
。我和其他似乎有类似问题的人一起查看了505的反应。显然505表示HTTP版本不匹配,但是当我将相同的查询URL复制到任何浏览器(尝试过firefox,seamonkey和Opera)时,似乎没有问题。我读过的其中一篇文章建议浏览器可能会自动处理版本不匹配问题。
I have HTML based queries in my code and one specific kind seems to give rise to IOExceptions
upon receiving 505 response from the server. I have looked up the 505 response along with other people who seemed to have similar problems. Apparently 505 stands for HTTP version mismatch, but when I copy the same query URL to any browser (tried firefox, seamonkey and Opera) there seems to be no problem. One of the posts I read suggested that the browsers might automatically handle the version mismatch problem..
我试图通过使用附带的漂亮的开发人员工具深入挖掘Opera,看起来版本中没有不匹配(我相信Java使用HTTP 1.1)并且收到了一个不错的 200 OK
响应。当同一查询通过我的Java代码时,为什么会遇到问题?
I have tried to dig in deeper by using the nice developer tool that comes with Opera, and it looks like there is no mismatch in versions (I believe Java uses HTTP 1.1) and a nice 200 OK
response is received. Why do I experience problems when the same query goes through my Java code?
private InputStream openURL(String urlName) throws IOException{
URL url = new URL(urlName);
URLConnection urlConnection = url.openConnection();
return urlConnection.getInputStream();
}
示例链接: http://www.uniprot .org / uniprot /?query = mnemonic%3aNUGM_HUMAN& format = tab& columns = id,entry%20name,review,organism,length
推荐答案
Tomcat中存在一些问题,其中包含空格的URL。要解决此问题,您需要使用 URLEncoder
对您的网址进行编码。
There has been some issues in Tomcat with URLs containing space in it. To fix the problem, you need to encode your url with URLEncoder
.
示例(注意空格):
String url="http://example.org/test test2/index.html";
String encodedURL=java.net.URLEncoder.encode(url,"UTF-8");
System.out.println(encodedURL); //outputs http%3A%2F%2Fexample.org%2Ftest+test2%2Findex.html
这篇关于java.io.IOException:服务器返回HTTP响应代码505的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!