Java simple code: java.net.SocketException: Unexpected end of file from server

后端 未结 8 1712
盖世英雄少女心
盖世英雄少女心 2020-12-01 10:23

I wrote some simple code in Java, the method should connect to the website and return the BufferedReader.

private BufferedReader getConnection(String url_a)          


        
相关标签:
8条回答
  • 2020-12-01 11:03

    I got this exception too. MY error code is below

            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod(requestMethod);
            connection.setRequestProperty("Content-type", "JSON");
    

    I found "Content-type" should not be "JSON",is wrong! I solved this exception by update this line to below

            connection.setRequestProperty("Content-type", "application/json");
    

    you can check up your "Content-type"

    0 讨论(0)
  • 2020-12-01 11:04

    I do get this error when I do not set the Authentication header or I set wrong credentials.

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