Solved

Extract Header from Byte Array

Posted on 2009-04-02
1
215 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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now