PowerShell's Invoke-RestMethod equivalent of curl -u (Basic Authentication)

后端 未结 8 1463
长发绾君心
长发绾君心 2020-11-28 06:41

What is the equivalent of

curl -u username:password ...

in PowerShell\'s Invoke-RestMethod? I tried this:

$sec         


        
8条回答
  •  情话喂你
    2020-11-28 07:29

    This is the only method that worked for me so far:

    $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
    
    Invoke-RestMethod -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} ...
    

    But I don't believe there isn't a better way.

提交回复
热议问题