Handle special characters in username and password for curl command

curl is a solid and simple tool that allows transferring data from and to any server with command line using various protocols. Protocols supported are HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, DICT, TELNET, LDAP or FILE. This command is designed to work without any user interaction. It offers proxy support, user authentication, FTP uploading, HTTP posting, SSL connections, cookies, file transfer resume, Meta link, and many other features

You need to pass username and password to access a site, that requires http authentication, using curl command; Option ‘-u’ is available to pass username and password. Special character colon (:) is used as separator between them like <username>:<password>

curl -u username:password http://forkedblog.com

Now sometimes username and/or password contains special characters like exclamation mark, slash etc. In such scenarios, passing username and password with above pattern (user/name:pass!word) will not work. curl simply does not support special characters directly.

curl -u user!name:pass\word http://forkedblog.com

The above request will not succeed. To overcome failure in scenarios like this, you need to pass username and password values by escaping the special characters with back slash ‘\’

curl -u user\!name:pass\word http://forkedblog.com

Leave a Reply

avatar
  Subscribe  
Notify of