Movatterモバイル変換


[0]ホーム

URL:


everything curl

    Arguments to options

    Not all options are just simple boolean flags that enable or disablefeatures. For some of them you need to pass on data, like perhaps a usernameor a path to a file. You do this by writing first the option and then theargument, separated with a space. Like, for example, if you want to send anarbitrary string of data in an HTTP POST to a server:

    curl -d arbitrary http://example.com

    and it works the same way even if you use the long form of the option:

    curl --data arbitrary http://example.com

    When you use the short options with arguments, you can, in fact, also write thedata without the space separator:

    curl -darbitrary http://example.com

    Arguments with spaces

    At times you want to pass on an argument to an option, and that argumentcontains one or more spaces. For example you want to set the user-agent fieldcurl uses to be exactlyI am your father, including those three spaces. Thenyou need to put quotes around the string when you pass it to curl on thecommand line. The exact quotes to use varies depending on your shell/commandprompt, but generally it works with double quotes in most places:

    curl -A "I am your father" http://example.com

    Failing to use quotes, like if you would write the command line like this:

    curl -A I am your father http://example.com

    … makes curl only use 'I' as a user-agent string, and the following strings,am,your andfather are instead treated as separate URLs since they donot start with- to indicate that they are options and curl only everhandles options and URLs.

    To make the string itself contain double quotes, which is common when you forexample want to send a string of JSON to the server, you may need to usesingle quotes (except on Windows, where single quotes do not work the sameway). Send the JSON string{ "name": "Darth" }:

    curl -d '{ "name": "Darth" }' http://example.com

    Or if you want to avoid the single quote thing, you may prefer to send thedata to curl via a file, which then does not need the extra quoting. Assumingwe call the file 'json' that contains the above mentioned data:

    curl -d @json http://example.com

    [8]ページ先頭

    ©2009-2025 Movatter.jp