Click here to Skip to main content
12,761,424 members (36,434 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


5 bookmarked
Posted 27 Apr 2014

RESTful Webservice Testing Using cURL on Windows

, 28 Apr 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
RESTful Webservice Testing Using cURL on Windows

Testing RESTful webservices on Windows can be done outside of the browser using an open source command tool called cURL, which can be donwloaded at After downloading the Windows version based on your operation system, remember to add the location of the cURL binary to your system’s path environment variable.

The advantage of cURL over conventional forms such as browser is the ability to automate testing tasks and execute different types of HTTP requests. See the cURL online documentation for details.

Assume you have a RESTFul webservice available locally at http://localhost:8080/controlroomws. This webservice exposes a list of users via /UserList and the details of a specific user can be retrieved via /UserList/username. Through the webservice API, you can also persist users to a back end database using an HTTP POST request.

Say we will like to persist the following user to the back end database via the webservice API:

<user role="ROLE_OPERATOR" loginName="test_login1"></user>

Submitting an HTTP POST using inline XML will not work. For example, running this on the command line will return an exception:

curl -X POST -d "<userList xmlns="urn:user"><user role="ROLE_OPERATOR" 
loginName="chuck_norris"></user></userList>" -H "Content-Type: application/xml" 
--basic --user username:password http://localhost:8080/controlroomws/UserList/

as posted in this StackOverflow thread.

To circumvent this problem, create an XML file containing your data and submit to the RESTful service as follows:

curl -X POST -d @userList.xml -H "Content-Type: application/xml" 
--basic --user username:password http://localhost:8080/commandcontrolws/UserList

To confirm that your data has been persisted to the underlying data store, perform a HTTP GET request that will return the list of users as follows:

curl -X GET --basic --user username:password http://localhost:8080/commandcontrolws/UserList

To return details of the specific user you just added, issue another HTTP GET command:

curl -X GET --basic --user username:password http://localhost:8080/commandcontrolws/UserList/chuck_norris


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Nji, Klaus
Canada Canada
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 28 Apr 2014
Article Copyright 2014 by Nji, Klaus
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid