3

The command

curl http://localhost/ --data @hello

will try to read from file hello. How do I escape the @ symbol?

1
  • @stArdustͲ: not in curl 7.36.0 Commented Mar 31, 2015 at 16:02

3 Answers 3

3

Without trying to find out more about the internals of curl, I would suggest just piping into it:

printf @hello | curl http://localhost/ --data @-

As @ulrich-schwarz suggested in a comment, you could also use --data @<(echo @hello) if it's more convenient (not all shells support this syntax).

Looking at the source code for curl-7.41.0, I don't see any way to escape a @ sign to prevent interpretation as a file name:

if('@' == is_file) {
  /* a '@' letter, it means that a file name or - (stdin) follows */

  if(curlx_strequal("-", p)) {
    file = stdin;
    set_binmode(stdin);
  }
  else {
    file = fopen(p, "rb");
    if(!file)
      warnf(config,
            "Couldn't read data from file \"%s\", this makes "
            "an empty POST.\n", nextarg);
  }

  /* ... */
}

So, unfortunately, it looks like we are stuck with the piping solution above.

2
  • In case of multiple such items: curl http://localhost:8080 --data @<(echo '@hello') or variations thereon should also work. Commented Mar 31, 2015 at 16:08
  • Thanks, @UlrichSchwarz, I integrated this solution into my answer. Commented Mar 31, 2015 at 16:14
1

From curl man page:

--data-raw <data>

(HTTP) This posts data similarly to -d, --data but without the special interpretation of the @ character.

So your command should be

0

The data is sent with the content type application/x-www-form-urlencoded. In principle, %40 should be decoded to @, so the following command should send equivalent data:

curl http://localhost/ --data %40hello

However this may or may not work depending on whether the server-side application actually performs URL decoding. If it expects unencoded data, which is fairly common when the application didn't expect the data to contain any special character, the application may interpret this as %40hello.

If the application doesn't do decoding, pipe the data to curl.

1
  • That didn't work for me. :-/ Commented Apr 2, 2015 at 14:38

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.