gpt4 book ai didi

PowerShell 的 Invoke-RestMethod 相当于curl -u(基本身份验证)

转载 作者:行者123 更新时间:2023-12-02 23:19:02 24 4
gpt4 key购买 nike

相当于什么

curl -u username:password ...

在 PowerShell 的 Invoke-RestMethod 中?我试过这个:

$securePwd = ConvertTo-SecureString "password" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ($username, $securePwd)

Invoke-RestMethod -Credential $credential ...

但它返回 401,未经授权。

最佳答案

这是迄今为止唯一对我有用的方法:

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

Invoke-RestMethod -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} ...

但我不相信没有更好的方法。

关于PowerShell 的 Invoke-RestMethod 相当于curl -u(基本身份验证),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24672760/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com