Reputation: 24005
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?
Upvotes: 3
Views: 1281
Reputation: 718856
(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 ...
Upvotes: 1