Send HTTP request manually via socket

后端 未结 4 693
[愿得一人]
[愿得一人] 2020-11-28 05:15

When I send a normal HTTP request via a socket, the server does not respond with an OK response. I copied the HTTP header from Firefox. Here is the code:

Soc         


        
4条回答
  •  抹茶落季
    2020-11-28 06:07

    The following fix, as mentioned by the previous answers, solves the problem;

    pw.print("GET / HTTP/1.1\n\r\n");
    pw.print("Host: stackoverflow.com\n\r\n");
    

提交回复
热议问题