What does '--user' mean with curl

后端 未结 4 2012
傲寒
傲寒 2020-12-29 19:15

I\'m working with an API and I have to send a POST request. I know how to set a header (-H) and (-d) is the body, but what is \"--user\".

If I submit this with Postm

4条回答
  •  没有蜡笔的小新
    2020-12-29 20:14

    Late to the party, but here goes...

    You can use curl with the -v (verbose) parameter to see the headers sent. You will then see that the information provided with --user is transformed into a header, such as:

    Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l
    

    The text after the Basic keyword is a base64 encoded text string of the username:password combination provided with the --user parameter

    To manually generate the base64 encoded credentials on Linux, you can simply call:

    echo -n "username:password" | base64 -w0
    

    For windows, save the "username:password" to a file, then use certutil.exe to create a base64 encoded file:

    certutil -encode credentials.txt credentials.asc
    

    To test this end to end, you can remove --user username:password and substitute with --header Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l and it will still authenticate just fine.

    To do this manually without curl, you would need to base64 encode username:password combination. You would then need to set the HTTP Authorization header with the type as Basic along with the base64 encoded string.

提交回复
热议问题