解析原始HTTP请求 [英] Parsing raw HTTP Request

查看:114
本文介绍了解析原始HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究HTTP流量数据集,它由完整的POST和GET请求组成,如下所示。我在java中编写了代码,将每个请求分开并将其保存为数组列表中的字符串元素。 现在我很困惑如何在java中解析这些原始HTTP请求有没有比手动解析更好的方法?

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 and saved it as string element in array list. Now i am confused how to parse these raw HTTP request in java is there any method better than manual parsing?

GET http://localhost:8080/tienda1/imagenes/3.gif/ HTTP/1.1
User-Agent: Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.8 (like Gecko)
Pragma: no-cache
Cache-control: no-cache
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Encoding: x-gzip, x-deflate, gzip, deflate
Accept-Charset: utf-8, utf-8;q=0.5, *;q=0.5
Accept-Language: en
Host: localhost:8080
Cookie: JSESSIONID=FB018FFB06011CFABD60D8E8AD58CA21
Connection: close


推荐答案


我正在努力[一个HTTP流量数据集,由完整的POST和GET请求组成[s]

I [am] working on [an] HTTP Traffic Data set which is composed of complete POST and GET request[s]

所以你要解析一个文件或列表包含多个HTTP请求。您要提取哪些数据?无论如何这里是一个Java HTTP解析类,它可以读取请求行中使用的方法,版本和URI,它将所有标题读入Hashtable。

So you want to parse a file or list that contains multiple HTTP requests. What data do you want to extract? Anyway here is a Java HTTP parsing class, which can read the method, version and URI used in the request-line, and that reads all headers into a Hashtable.

如果你想重新创建,你可以使用那个或自己写一个车轮。查看 RFC ,了解要解析的请求是什么样的它正确:

You can use that one or write one yourself if you feel like reinventing the wheel. Take a look at the RFC to see what a request looks like in order to parse it correctly:

Request       = Request-Line              ; Section 5.1
                    *(( general-header        ; Section 4.5
                     | request-header         ; Section 5.3
                     | entity-header ) CRLF)  ; Section 7.1
                    CRLF
                    [ message-body ]          ; Section 4.3

这篇关于解析原始HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆