简体   繁体   English

想要只在我的输出中打印正文部分而不是http标题。.Http请求是使用套接字编程处理的

[英]Want to print only body part in my output not the http headers.. Http Request is handled using socket programming

I've written a server socket code that receives http request and print it on console. 我已经编写了一个服务器套接字代码,用于接收http请求并将其打印在控制台上。

Given below is the server code. 下面是服务器代码。

clientSocket = echoServer.accept();
is = new DataInputStream(clientSocket.getInputStream());
while (true) 
{
    line = is.readLine();
    System.out.println(line);
}

The output is: 输出为:

POST / HTTP/1.1

User-Agent: Java/1.6.0_20

Host: 127.0.0.1:4000

Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2

Connection: keep-alive

Content-type: application/x-www-form-urlencoded

Content-Length: 7

   Hello

I don't want header in my output, How can I get only Body part in my output that is "Hello"? 我不想在输出中使用标题,如何在输出中仅获得“ Hello”的主体部分?

HTTP requests starts with a status line followed by header lines followed by the body. HTTP请求以状态行,标题行,正文开头。 the request/header lines are separated by a single CRLF ( \\r\\n ), but the body is separated from them with additional CRLF : 请求/标题行由单个CRLF\\r\\n )分隔,但正文与附加CRLF分开:

POST / HTTP/1.1
User-Agent: Java/1.6.0_20
Host: 127.0.0.1:4000
Accept: text/html, image/gif, image/jpeg, *; q=.2, /; q=.2
Connection: keep-alive
Content-type: application/x-www-form-urlencoded
Content-Length: 7

Hello

Eg you need to look for the first empty line. 例如,您需要寻找第一个空行。 after than the body starts. 之后比身体开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM