Hellow there folks! These days most of the web services are exposed as REST or 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 curl it can transfer data using various protocols. If you don’t have curl installed use the below command.

 

SOAP Request Flow

SOAP request
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.

 

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.

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

Example O/P

 

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

37 Comments

  1. Payam January 30, 2015 at 7:44 pm

    That was the quickest and most effective way to learn how to send SOAP request via cURL.
    Thanks!

    Reply
  2. MJ April 14, 2015 at 8:36 pm

    Thanks much for the information.

    Reply
  3. MJ April 14, 2015 at 8:38 pm

    how can we send the user authentication info in a script using CURL? i would like to mask the password file as well.

    Reply
    1. Dasun Hegoda April 16, 2015 at 3:01 am

      If I understand your question right, what you can do is you can send the file as an attachment as shown below.

      Reply
      1. Gabriel Terra Oliveira November 25, 2016 at 2:13 pm

        First, thanks for share this article, helps much!
        So, can I use the authentication on request.xml file?

        Reply
  4. mooreds May 5, 2015 at 2:09 pm

    Thanks, very helpful.

    Reply
  5. Tiago Feitor May 15, 2015 at 4:40 pm

    Hi

    When I tried this:

    {quote}
    /opt/freeware/bin/curl -H “Content-Type: text/xml; charset=utf-8” -H “SOAPAction:urn:test” -d @$f -X POST http://127.0.0.1:9080/services/testServices
    {quote}

    I got the following error:

    {quote}
    You can only select one HTTP request!
    {quote}

    How can solve this problem??

    thanks in advance
    Tiago

    Reply
  6. Pingback: Using Curl | RaSor's Tech Blog

  7. BrownsFan June 3, 2015 at 12:04 am

    Superb. I was able to adapt it to SOAP messages we use for testing and it worked. Thanks so much. :)

    Reply
    1. Dasun Hegoda June 3, 2015 at 8:05 am

      There are a lot articles written on the particular subject. Please Google

      Reply
  8. Ancuta C September 17, 2015 at 9:26 pm

    Thanks for the help! Is very usefull!

    Reply
  9. Roberto October 6, 2015 at 2:37 pm

    I have an error:

    soap:ClientUnmarshalling Error: java.lang.IllegalArgumentException:

    Reply
  10. redvoid October 6, 2015 at 10:35 pm

    exactly what I needed with no fluff. very clear. I was able to automate SOAP calls from Jenkins with this in minutes after struggling prior. Thanks!

    Reply
  11. Miguel Angel Lara Rocha February 26, 2016 at 5:52 pm

    Hello I am trying to access BMC Remedy Webservices by using this method but it does not work, althougth it has work with other web services and BMC Remedy’s Web service works with a SOA Client UI. When I Invoke the WS using curl it returns java.lang.null.pointer.exception. the same XML input is working on the SOA Client. Any Ideas about what might be wrong?

    Reply
  12. Lucas March 10, 2016 at 9:05 pm

    Hello, what if the “SoapAction” is Soapction=”” in the wsdl file?

    Reply
    1. Enrique SM October 27, 2016 at 10:16 am

      You must escape the ” character like this ”

      “SoapAction=”””

      Reply
  13. Pingback: Let’s make a SOAP request from command line(curl)? – Dasun Hegoda – 小亮 (Oscar) 書籤

  14. Pooyan Najafi April 26, 2016 at 10:57 pm

    I searched all around the net for a solution of SOAP using Node JS (because need SOAP service to set up data on Protractor) and my brain went fried as I could not use any examples. Now wanting to use Jenkins to call SOAP before running Protractor and seeing this post solution work with my WSDL is a definite joy! Thanks soooo much!

    Reply
  15. Sambasivarao Kurakula July 16, 2016 at 8:14 am

    Sir how to send XML object that is not in file to server using c++ cpr.
    Please give me the example send function syntax.Thanks in advance.Please give me reply.

    Reply
  16. Mahesh Kumar November 8, 2016 at 11:43 am

    I am posting below soap xml

    curl -X POST –header “Content-Typ_SERVICE_ENDPOINT” -d –data-urlencode ‘xmlRequest=Make My TripSrinu Muppananon-refundable booking’ http://testuzz.cultuzz.com:8080/cultagent/services/GetResService/processMakeMyTripRQ -v

    I got below example

    org.apache.axis2.AxisFault: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character ‘-‘ (code 45) in prolog; expected ‘<‘

    at [row,col {unknown-source}]: [1,1]

    at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)

    at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:175)

    at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:142)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)

    Reply
    1. Mahesh Kumar November 8, 2016 at 11:44 am

      Could please help for find out the problem

      Reply
      1. Sanketh Vijay June 11, 2019 at 12:56 pm

        I’m also trying the same thing. I wanted to send soap request xml as an argument rather than reading from the file. Did you find any solution to this?

        Reply
        1. Mahith Kumar January 21, 2020 at 11:17 am

          im trying to find the same, please help me with that

          Reply
  17. Pingback: SOAP calls from python [links] – dbarenas

  18. qmailMadrid May 9, 2017 at 4:33 am

    Really love this article. Let me repost on my blog for my own documentation.

    Reply
  19. Pingback: REPOST : Let’s make a SOAP request from command line (curl)? – @ykzir

  20. ВладКрас June 2, 2017 at 4:27 am

    if you need curl with basic auth add --user login:pass to args

    Reply
  21. STK September 8, 2017 at 2:00 pm

    Thank you for sharing.
    Helped me a lot in debugging an issue.

    Reply
  22. Umashankar Jhajharia November 9, 2017 at 8:46 am

    Right now I am trying to call a Web service using Curl command from Unix platform. The Web service is available on external server. I can connect the external server using telnet only. The Web service uses basis authentication and I have to provide a username and password.

    Can anyone please help me with correct way to execute this ?

    Reply

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.