Let's make a SOAP request from command line(curl)?

Hellow there folks! These days most of the web services are exposed as RESTor SOAP. There could be a chance where you need to make a request from your command line rather than installing a tool such SOAPUI. Tools are really helpful but there are times where you can’t use tools. I’ll be using curl to make the request. if you don’t know about curlit can transfer data using various protocols. If you don’t have curl installed use the below command.

sudo apt-get install curl

 

SOAP Request Flow

Let's make a SOAP request from command line(curl)?_第1张图片Image Courtesy : java-forums.org

Step 1

Let’s create a SOAP envelope as below which is the SOAP request to be sent via curl. Create a file with the below content named “request.xml”. The SOAP envelope and the SOAP request parameters depend on your web service.





?
?


 

Step 2

Let’s make a request using the curl command.

curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction: ACTION_YOU_WANT_TO_CALL" --data @FILE_NAME URL_OF_THE_SOAP_WEB_SERVICE_ENDPOINT

 

Below mentioned should be replaced according to your web service.

  1. ACTION_YOU_WANT_TO_CALL
  2. FILE_NAME
  3. URL_OF_THE_SOAP_WEB_SERVICE_ENDPOINT

See the example below to get an idea.

curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:urn:GetVehicleLimitedInfo" --data @request.xml http://11.22.33.231:9080/VehicleInfoQueryService.asmx

See the sample O/P below. You should get a similar O/P according to your web service.

Example O/P







1411050004
200
GP-XXYY

4G13-YX59ZC
MOTOR CAR
MITSUBISHI
LANCER
1999
0




 

Hope you got an idea how to make a request SOAP request using command line. If you have any questions let me know in the comments below. Your feedback is highly appreciated(happy-face).

你可能感兴趣的:(Let's make a SOAP request from command line(curl)?)