0

I am updating a password for the user using curl.

When I update the password with special characters, curl requests gets failed.

Curl Request:-

curl -v -f -u "admin:admin" "https://sample.com/users/1?pretty=true" -X PUT -F "password=@68bnD2vRQ"

Error:-

couldn't open file "68bnD2vRQ"

How can I use the curl requests with special characters for PUT method?

FYI I am generating and assigning random password for the users. So I am not sure the position of special characters in the password, it may be any where in the string.

Vega
  • 27,856
  • 27
  • 95
  • 103
Galet
  • 5,853
  • 21
  • 82
  • 148
  • 3
    Possible duplicate of [curl - How to escape < in parameter value](https://stackoverflow.com/questions/25484313/curl-how-to-escape-in-parameter-value) – orhtej2 Oct 04 '17 at 07:12
  • @orhtej2 Is there any special characters gets conflict in curl like '@' and '<' ? Because my random password contain these (!@#$%^&*+=) special characters. Will this "--form-string" is enough or need to any other solutions based on my above special characters? – Galet Oct 04 '17 at 07:21
  • --form-string only disables special meaning of < and @, see other special characters in https://curl.haxx.se/docs/manpage.html (--form). Notice that it depends on how you invoke curl - perhaps some of these are special characters in the shell you're using? – orhtej2 Oct 04 '17 at 07:41
  • @orhtej2 I am not able to use "$" symbol in password string as it conflict with shell script. mypassword=$68bnD2vRQ , When I use password=$mypassword, curl request result in an error due to "$" symbol – Galet Oct 04 '17 at 10:28
  • 1
    It needs to be escaped, depends on the exact shell you're using. Something like https://stackoverflow.com/a/2856010/7034621 ? – orhtej2 Oct 04 '17 at 10:48

1 Answers1

0

Try passing the data from the standard input:

$ curl -X PUT http://httpbin.org/put -d@-
password=@68bnD2vRQ

The -d@- reads data from stdin.

Just in case by pressing ctrl+D terminates the input.

nbari
  • 25,603
  • 10
  • 76
  • 131