Solved

Extract Header from Byte Array

Posted on 2009-04-02
1
223 Views
Last Modified: 2013-11-23
I have a JAVA byte array which basically contains an http GET request.   That's what's I'm stuck with.  The real GET request looks like below in code window.

I need to extract header information from the byte array as a name value pair.  For example, the first set of values would look like this:
name= Host
value=www.msnbc.msn.com

GET requests will vary so the routine needs to handle *any* GET request.  That is, the number of name value pairs will vary.

I need each name value pair back as strings so I can place each value into another class.

It would be great if there was a routine that could do this like, GetNameValuePair (byte[] greq)

Would anyone be willing to provide a routine that could do this?





Realistic GET request stored in a byte array
----------------------------------------------------
GET / HTTP/1.1
Host: www.msnbc.msn.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12\n

Open in new window

0
Comment
Question by:lcor
1 Comment
 
LVL 9

Accepted Solution

by:
brunoguimaraes earned 500 total points
ID: 24050043
You could use a Properties object.
byte[] header = // your byte array
 
Properties prop = new Properties();
 
prop.load(new ByteArrayInputStream(header));
 
// then you can retrieve the values this way:
prop.get("Host"); // prints www.msnbc.msn.com
 
// and so on...

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
netstat -ano | find "8000" and taskkill /f /pid 2984 3 83
Configure a Bean in an XML file 4 42
Is there a simpler dropbox system? 10 34
asp Google Map 2 32
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question