34

I am using Apache Commons HttpClient PostMethod 3.1.

In the PostMethod class there are also three methods for setting POST method's request body:

setRequestBody(InputStream body)
setRequestBody(String body)
setRequestBody(NameValuePair[] parametersBody);

NameValuePair API

First two methods are deprecated. Does anybody knows why? Because if I want to put an XML to request body, NameValuePair does not help me.

Does anybody knows an workaround or a solution?

2 Answers 2

49

The javadoc says:

Deprecated. use setRequestEntity(RequestEntity)

RequestEntity has a lot of implementors, namely:

ByteArrayRequestEntity, FileRequestEntity, InputStreamRequestEntity, MultipartRequestEntity, StringRequestEntity

Use the one that suits you:

and so on.

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

1 Comment

StringRequestEntity not found in Suggestion.
5

Yes, so for example,

post.setRequestEntity( new StringRequestEntity( xml ) );

instead of

post.setRequestBody( xml );

1 Comment

Unfortunately the constructor StringRequestEntity(String) is deprecated now too. Instead you'll have to use: post.setRequestEntity(new StringRequestEntity(xml, "text/xml", "ISO-8859-1"));

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.