소켓을 통해 정상적인 HTTP 요청을 보내면 서버가 OK 응답으로 응답하지 않습니다. Firefox에서 HTTP 헤더를 복사했습니다. 다음은 코드입니다.
Socket s = new Socket(InetAddress.getByName("stackoverflow.com"), 80);
PrintWriter pw = new PrintWriter(s.getOutputStream());
pw.print("GET / HTTP/1.1");
pw.print("Host: stackoverflow.com");
pw.flush();
BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
String t;
while((t = br.readLine()) != null) System.out.println(t);
br.close();
그러나 다음은 내가받은 응답입니다.
HTTP/1.0 408 Request Time-out
Cache-Control: no-cache
Connection: close
Content-Type: text/html
<html><body><h1>408 Request Time-out</h1>
Your browser didn't send a complete request in time.
</body></html>
을 사용하여이 작업을 수행 할 수 있다는 것을 알고 URL.openStream()
있지만 수동으로 보낼 때 서버가 HTTP 요청을 식별하지 못하는 이유는 무엇입니까?
두가지:
println
대신 print
별도의 라인 항목을 인쇄 할 수 있습니다.pw.println("");
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다