3

Is there a way to add raw bytes to the post parameters using Apache's HTTPClient? My motivation is to stream the raw bytes of a stream in a particular encoding and then test what happens to that data when it gets to the server.

edit: I noticed that Apache has a deprecated method to add to the request body using an inputstream, so I could feed this a ByteArrayInputStream, but is there anything better/ not deprecated?

1 Answer 1

1

(You didn't specify, so I'm assuming you are using Apache HttpClient version 4.x)

I don't think you can "add" raw bytes to an normally create request's POST parameters.

However, it should be possible to create a PostMethod with an HttpEntity which consists of legitimate parameters, plus some incorrectly encoded stuff. You may need to do the formatting and encoding of the content yourself, but you might be able to take a short cut by putting the valid parameters into a UrlEncodedFormEntity, and then using the writeTo method to extract the formatted/encoded version into a ByteArrayOutputStream. After you've hacked the content bytes, turn them into a ByteArrayEntity instance with the appropriate content type and encoding parameters.

It will be messy ...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.