尝试使用套接字检索页面时,请继续获取相同的错误代码(错误请求)

时间:2017-12-24 10:21:30

标签: java sockets web

我试图使用Socket获取网页并获取请求,但我一直收到相同的错误 - 错误的请求,对于我尝试使用它的任何网站或网页。

    Socket s = new Socket("horstmann.com", 80);

    InputStream in = s.getInputStream();
    OutputStream out = s.getOutputStream();

    Scanner reader = new Scanner(in);
    PrintWriter writer = new PrintWriter(out, false);

    String command = "GET / HTTP/1.0\n\n";
    //System.out.print(command);
    writer.print(command);
    writer.flush();

    while (reader.hasNextLine()) {
        System.out.println(reader.nextLine());
    }
    s.close();

1 个答案:

答案 0 :(得分:1)

试试这个:

.vimrc