开发者

Parsing HTTP Get requests into constituent fields

开发者 https://www.devze.com 2023-01-19 08:45 出处:网络
I have fields like: \"GET /?blahblahblah HTTP/1.1\" 200 43 \"http://www.thesun.co.uk/sol/homepage/\" 1 blahblah - \"en-gb\" \"Mozilla/4.0 (compatible; MSI开发者_JS百科E 7.0; Windows NT 5.1; Trident/

I have fields like:

"GET /?blahblahblah HTTP/1.1" 200 43 "http://www.thesun.co.uk/sol/homepage/" 1 blahblah - "en-gb" "Mozilla/4.0 (compatible; MSI开发者_JS百科E 7.0; Windows NT 5.1; Trident/4.0; GTB0.0; FunWebProducts; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"

i'm looking for a java library or code that can decode this, parse it apart, and provide programatic access to the components, especially the user agent info. googling didnt turn up anything useful, but as this info is used all the time, there must be existing systems for doing what i require.


You probably want to use Apache HttpCore. The interface you're looking for it HttpRequest and a simple implementation is BasicHttpRequest.

Constructing the HttpRequest is dependent on how you get the request itself to begin with, but for example, in a little web server I'm working on, it's simply:

DefaultHttpServerConnection serverConnection = new DefaultHttpServerConnection();
serverConnection.bind(socket, params);
HttpRequest httpRequest = serverConnection.receiveRequestHeader();


What you are looking for is an apache LOG parser. You may find JXLA useful, or google for "Java apache log parser".

0

精彩评论

暂无评论...
验证码 换一张
取 消