Horstmann의 Big Java과 함께 Java로 서버를 구축하는 중입니다. "단순히 호스트에 연결을 설정하고 호스트에 GET
명령을 보내고 서버가 연결을 종료 할 때까지 서버에서 입력을받는 프로그램을 마쳤을 때"나는 내 웹 사이트에서 시도하기로 결정했습니다.Java 서버의 이상한 출력 - 내 사이트가 어떻게 든 해킹 당했습니까?
반환 된 코드는 이 아닙니다.은 what the html on my site looks like입니다. 실제로, 그것은 내 사이트를 완전하고 완전히 납치 한 것처럼 보입니다. 물론 사이트 자체는 여전히 항상 같아 보입니다 ...
나는 여기에서 내가 무엇을 보는지 정말로 확신하지 못합니다. 코드가 맞는지 두 번 확인했습니다. Java 측에서 문제가 발생 했나요? 아니면 제 편이 뭔가요? 이제
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;
public class WebGet {
public static void main(String[] args) throws IOException {
// Get command-line arguments
String host;
String resource;
if (args.length == 2) {
host = args[0];
resource = args[1];
} else {
System.out.println("Getting/from thelinell.com");
host = "thelinell.com";
resource = "/";
}
// Open Socket
final int HTTP_PORT = 80;
Socket s = new Socket(host, HTTP_PORT);
// Get Streams
InputStream instream = s.getInputStream();
OutputStream outstream = s.getOutputStream();
// Turn streams into scanners and writers
Scanner in = new Scanner(instream);
PrintWriter out = new PrintWriter(outstream);
// Send command
String command = "GET " + resource + "HTTP/1.1\n" + "Host: " + host + "\n\n";
out.print(command);
out.flush();
// Read server response
while (in.hasNextLine()) {
String input = in.nextLine();
System.out.println(input);
}
// Close the socket
s.close();
}
}
, 광고의 무리처럼 외모를 반환 오히려 긴되는 코드 : 여기
는 자바이다. 간결함을 위해 나에게주는 것은 pastebin입니다. 요청하면 여기에 추가하겠습니다.String command = "GET " + resource + "HTTP/1.1\n" ...
가되어야한다 :
사실, 유효한 요청입니다. [Simple-Request] (http://www.w3.org/Protocols/HTTP/1.0/draft-ietf-http-spec.html#Request) (적어도 첫 번째 줄, 두 번째 줄 무시), 서버의 기본 도메인에서'/ HTTP/1.1'을 가져 오려고 시도합니다. – mata
그리고 나는 스스로에게 전화를 걸었다. 당신이 올바른지! – Linell
@mata - Simple-Request에 호의적입니다. – Perception