Parsing raw HTTP Request

前端 未结 3 1596
逝去的感伤
逝去的感伤 2020-12-09 12:58

I working on HTTP Traffic Data set which is composed of complete POST and GET request Like given below. I have written code in java that has separated each of these request

3条回答
  •  [愿得一人]
    2020-12-09 13:44

    If you just want to send the raw request as it is, it's very easy, just send the actual String using a TCP socket!

    Something like this:

        Socket socket = new Socket(host, port);
    
        BufferedWriter out = new BufferedWriter(
                new OutputStreamWriter(socket.getOutputStream(), "UTF8"));
    
        for (String line : getContents(request)) {
            System.out.println(line);
            out.write(line + "\r\n");
        }
    
        out.write("\r\n");
        out.flush();
    

    See this blog post by JoeJag for the full code.

    UPDATE

    I started a project, RawHTTP to provide HTTP parsers for request, responses, headers etc... it turned out so good that it makes it quite easy to write HTTP servers and clients on top of it. Check it out if you're looking for something lowl level.

提交回复
热议问题