Bir tane boş satır attıktan sonra gelen veriler body olarak ele alınıyormuş. Bu linkten kontrol edebilirsin.
Kod:
String crlf = "\r\n";
out.print("HTTP/1.1 200 OK" + crlf);
out.print("Content-Type text/plain" + crlf);
/*
* At that point, read HTTP request and send it back to the
* client.
*/
out.print(crlf);
String line;
while ((line = in.readLine()) != null) {
if (line.length() == 0)
break;
out.print(line + crlf);
System.out.println(line);
}
Aşağıdaki kodu ceviz.net' in cevabını görmek için kullandım. Belki işine yarar.
Kod:
try {
Socket socket = new Socket("www.ceviz.net", 80);
OutputStream os = socket.getOutputStream();
PrintWriter writer = new PrintWriter(os);
String crlf = "\r\n";
writer.write("GET / HTTP/1.1" + crlf);
writer.write("Host: www.ceviz.net:80" + crlf);
writer.write("User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1" + crlf);
writer.write("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" + crlf);
writer.write("Accept-Language: en-us,en;q=0.5" + crlf);
writer.write("Accept-Encoding: gzip, deflate" + crlf);
writer.write("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" + crlf);
writer.write("DNT: 1" + crlf);
writer.write("Connection: keep-alive" + crlf);
writer.write(crlf + crlf);
writer.flush();
InputStream is = socket.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line = null;
while( (line=reader.readLine()) != null ) {
System.out.println(line);
}
reader.close();
socket.close();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Yer İmleri