简体   繁体   中英

How to run HTTPPost call service?

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM