java.io.IOException: Server returns HTTP response code 505

前端 未结 5 916
北海茫月
北海茫月 2020-12-15 20:11

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

相关标签:
5条回答
  • 2020-12-15 20:15

    @posdef I was having same HTTP error code 505 problem. When I pasted URL that I was using in Java code in Firefox, Chrome it worked. But through code was giving IOException. But at last I came to know that in url string there were brackets '(' and ')', by removing them it worked so it seems I needed URLEncodeing same like browsers.

    0 讨论(0)
  • 2020-12-15 20:16

    Are you behind a proxy? This code works for me and prints out the same text I see through a browser.

    final URL url = new URL("http://www.uniprot.org/uniprot/?query=mnemonic%3aNUGM_HUMAN&format=tab&columns=id,entry%20name,reviewed,organism,length");
    final URLConnection conn = url.openConnection();
    final InputStream is = conn.getInputStream();
    System.out.println(IOUtils.toString(is));
    

    conn is an instance of HttpURLConnection

    0 讨论(0)
  • 2020-12-15 20:27

    from the API documentation for the URL class:

    The URL class does not itself encode or decode any URL components [...]. It is the responsibility of the caller to encode any fields, which need to be escaped prior to calling URL, and also to decode any escaped fields, that are returned from URL.

    so if you have any spaces in your url-str encode it before calling new URL(url-str)

    0 讨论(0)
  • 2020-12-15 20:28

    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.

    Example (notice the space):

    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
    
    0 讨论(0)
  • 2020-12-15 20:31

    AS a developer at www.uniprot.org I have the advantage of being able to look in the request logs. In the last year according to the logs we have not send a 505 response code. In any case our servers do understand http 1 requests as well as the default http1.1 (though you might not get the results that you expect).

    That makes me suspect there was either some kind of data corruption on the way. Or you where affected by a hardware failure (lately we have had some trouble with a switch and a whole datacentre ;). In any case if you ever have questions or problems with uniprot.org please contact help@uniprot.org then we can see if we can help/fix the problem.

    Your code snippet seems normal and should work.

    Regards, Jerven Bolleman

    0 讨论(0)
提交回复
热议问题