views:

973

answers:

1

I am curios about how one can set the request properties for a PostMethod in Apache Commons HttpClient?

I am refactoring some code written using HttpURLConnection class to post which looks like the following:

conn1.setRequestProperty(
    "Content-Type", "multipart/related; type=\"application/xml\"; boundary="
    + boundary);
conn1.setRequestProperty("Authorization", auth); 

... ...

To use:

PostMethod method = new PostMethod(_Server); 
method.setRequestBody(...); or 
method.setRequestHeader(...);

But i am not sure if / how this will map to what i want to do with the original URL class... can anyone help clarify how to set request properties with PostMethod class?

Thanks a lot!

-alex

+1  A: 

Those are both request headers, so you would need to call setRequestHeader() to establish those values on the connection. HttpClient also supports handling basic authentication so the "Authorization" header can be refactored out, depending on how deep your changes go.

eqbridges