0

问题

我认为 Credential Option 会向 requestHeader 添加一些内容,但看起来没有添加任何内容。凭据选项是否会更改 httpRequest 的其他部分?


环境

windows10
PowerShell 5.1.17134.765 使用 Fiddler4 分析请求。


执行命令

$cred = Get-Credential // input user and password
Invoke-WebRequest -Uri 'http://abc.xyz' -Credential $cred


请求内容(通过 Fiddler4):

原始标题

GET / HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT; Windows NT 10.0; ja-JP) 
WindowsPowerShell/5.1.17134.765
Host: abc.xyz

认证

No Proxy-Authorization Header is present.
No Authorization Header is present.
4

1 回答 1

1

According to the documentation, it will only supply the credentials to the remote server if the remote server sends an authentication challenge request.

So it won't do anything unless the target web server requests authentication.

You can apparently use it in conjunction with "-Authentication" to force it to try and authenticate with a specific type.

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-6

于 2019-07-10T00:22:42.263 回答