0

I have RESTfull service (Let say, http://apc.tr.re.er:5050/testxyz/service/loaninfo/) and i need to run POST service. I am using following classes :

HttpClient client = new DefaultHttpClient();  
HttpPost post = new HttpPost('above rest url'); <-----

And if I run code with above client and post I don't get the response as i would see in soapUI tool. And I am seeing the successful response from soapUI tool because I will be copying and pasting "XML" which has input values to be used by POST method.

I got stuck when i started using java to run above POST request . I need some help on "How to pass the input "XML" to POST service" ?

NOTE: I have managed to run HTTPRest request and got the required output, since request service doesn't need any input I don't see any complications. I am using JAVA as a code language.

Lucas
  • 14,227
  • 9
  • 74
  • 124
MKod
  • 803
  • 5
  • 20
  • 33

1 Answers1

0

You have to do something like the following.

MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
entity.addPart("xml", new StringBody("YOUR XML DATA"));
post.setEntity(entity);
Pradeep Pati
  • 5,779
  • 3
  • 29
  • 43
  • Thanks man. I am wondering what the "MultipartEntity" class does ? And, what is the purpose of ENUM Constant "HttpMultipartMode.BROWSER_COMPATIBLE" ? what the method "addpart" is doing ? Prior to this i am interested in knowing "Do I have to pass the whole XML into StringBody OR just the inputs ?". >>> There is no much information about MultipartEntity class and its usage that can be easily consumed or to understand by average coding peole like me. sorry to bother you friend. Help is appreciated from any one on this stackoverflow site. – MKod Apr 25 '13 at 03:14
  • http://hc.apache.org/httpcomponents-client-ga/httpmime/apidocs/org/apache/http/entity/mime/MultipartEntity.html – Pradeep Pati Apr 25 '13 at 04:23