繁体   English   中英

如何将 PowerShell invoke-webrequest 与 Windows 身份验证和用户名\\密码一起使用

[英]How to use PowerShell invoke-webrequest with Windows Authentication and Username\Password

当我运行它的 Windows 服务有权调用 web 服务时,以下 PowerShell invoke-webrequest 对我有用。 然而,情况并非总是如此。

我需要能够使用 Windows 身份验证,但还需要为呼叫设置帐户用户名\\密码。 有没有人有一些示例代码来执行此操作?

Invoke-WebRequest -UseBasicParsing "url" -UseDefaultCredentials -Method GET

您可以将Invoke-WebRequest模块的UseDefaultCredentials属性设置为true 官方文档链接: https : //docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest? view =powershell-6

$url = "http://yourURL"
$wc = New-Object System.Net.WebClient
$wc.UseDefaultCredentials = $true
$response = $wc.DownloadString($url)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM