Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Extract Header from Byte Array

Posted on 2009-04-02
1
Medium Priority
?
245 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to dynamically set the form action using jQuery.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

916 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