[英]How to use PowerShell invoke-webrequest with Windows Authentication and Username\Password
The following PowerShell invoke-webrequest works for me when the Windows Service I'm running it from has permission to call the webservice.当我运行它的 Windows 服务有权调用 web 服务时,以下 PowerShell invoke-webrequest 对我有用。 However, this isn't always the case.
然而,情况并非总是如此。
I need to the ability to use Windows Authentication but also set the account username\\password for the call.我需要能够使用 Windows 身份验证,但还需要为呼叫设置帐户用户名\\密码。 Does anyone have some sample code for doing this?
有没有人有一些示例代码来执行此操作?
Invoke-WebRequest -UseBasicParsing "url" -UseDefaultCredentials -Method GET
You may set the UseDefaultCredentials
property of Invoke-WebRequest
module to true
.您可以将
Invoke-WebRequest
模块的UseDefaultCredentials
属性设置为true
。 Link to the official doc: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-6官方文档链接: 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.