Example usage of curl
curl is convenient for testing web services.
Note: You may also be interested in:
Examples:
curl -i --data @sample-input.xml \
--header Content-type:application/xml \
https://goyun.info
curl -i --data @sample-input.json \
--header Content-type:application/json \
https://goyun.info
curl -i -X GET https://goyun.info
curl -i --header Accept:application/json
-X GET https://goyun.info
curl -v -H "Content-Type: application/json" -X POST -d '{"user":{"firstName":"Foo","lastName":"Bar","emailAddress":"<your email address here>"}, "password":"password"}' https://goyun.info/rest/user
Common parameters are:
-i, --include
(HTTP) Include the HTTP-header in the output. The HTTP-header
includes things like server-name, date of the document, HTTP-
version and more...
-X, --request <command>
(HTTP) Specifies a custom request method to use when communicat‐
ing with the HTTP server. The specified request will be used
instead of the method otherwise used (which defaults to GET).
Read the HTTP 1.1 specification for details and explanations.
Common additional HTTP requests include PUT and DELETE, but
related technologies like WebDAV offers PROPFIND, COPY, MOVE and
more.
Normally you don't need this option. All sorts of GET, HEAD,
POST and PUT requests are rather invoked by using dedicated com‐
mand line options.
This option only changes the actual word used in the HTTP
request, it does not alter the way curl behaves. So for example
if you want to make a proper HEAD request, using -X HEAD will
not suffice. You need to use the -I, --head option.
(FTP) Specifies a custom FTP command to use instead of LIST when
doing file lists with FTP.
If this option is used several times, the last one will be used.
Note: You may also be interested in:
Examples:
curl -i --data @sample-input.xml \
--header Content-type:application/xml \
https://goyun.info
curl -i --data @sample-input.json \
--header Content-type:application/json \
https://goyun.info
curl -i -X GET https://goyun.info
curl -i --header Accept:application/json
-X GET https://goyun.info
curl -v -H "Content-Type: application/json" -X POST -d '{"user":{"firstName":"Foo","lastName":"Bar","emailAddress":"<your email address here>"}, "password":"password"}' https://goyun.info/rest/user
Common parameters are:
-i, --include
(HTTP) Include the HTTP-header in the output. The HTTP-header
includes things like server-name, date of the document, HTTP-
version and more...
-X, --request <command>
(HTTP) Specifies a custom request method to use when communicat‐
ing with the HTTP server. The specified request will be used
instead of the method otherwise used (which defaults to GET).
Read the HTTP 1.1 specification for details and explanations.
Common additional HTTP requests include PUT and DELETE, but
related technologies like WebDAV offers PROPFIND, COPY, MOVE and
more.
Normally you don't need this option. All sorts of GET, HEAD,
POST and PUT requests are rather invoked by using dedicated com‐
mand line options.
This option only changes the actual word used in the HTTP
request, it does not alter the way curl behaves. So for example
if you want to make a proper HEAD request, using -X HEAD will
not suffice. You need to use the -I, --head option.
(FTP) Specifies a custom FTP command to use instead of LIST when
doing file lists with FTP.
If this option is used several times, the last one will be used.
-d, --data <data>
(HTTP) Sends the specified data in a POST request to the HTTP
server, in the same way that a browser does when a user has
filled in an HTML form and presses the submit button. This will
cause curl to pass the data to the server using the content-type
application/x-www-form-urlencoded. Compare to -F, --form.
-d, --data is the same as --data-ascii. To post data purely
binary, you should instead use the --data-binary option. To URL-
encode the value of a form field you may use --data-urlencode.
If any of these options is used more than once on the same com‐
mand line, the data pieces specified will be merged together
with a separating &-symbol. Thus, using '-d name=daniel -d
skill=lousy' would generate a post chunk that looks like
'name=daniel&skill=lousy'.
If you start the data with the letter @, the rest should be a
file name to read the data from, or - if you want curl to read
the data from stdin. The contents of the file must already be
URL-encoded. Multiple files can also be specified. Posting data
from a file named 'foobar' would thus be done with --data @foo‐
bar.
Comments
Post a Comment