取得的工作原理:.NET給人的GET請求400錯誤的請求。如果我在我的電腦上運行IE瀏覽器作爲用戶<code>DOMAINautomatic</code>網址某些服務器
right click IE
shift + right click "Internet Explorer" in the menu
run as different user
當打開URL http://server/ClearCache是沒有問題的。
當我使用PowerShell相同,如DOMAIN\automatic
再次運行下面的腳本運行:
$url = "http://server/ClearCache"
$req = [system.Net.WebRequest]::Create($url)
$req.UseDefaultCredentials = $true
$res = $req.GetResponse()
$res
路線ClearCache在控制器具有[AllowAnonymous]
。
當我去與遠程桌面服務器的登錄身份需要運行PowerShell腳本(SQL Server代理作業步驟)用戶DOMAIN\automatic
並運行腳本在PowerShell中,我得到:
Exception calling "GetResponse" with "0" argument(s): "The remote server returned an error: (400) Bad Request." At line:1 char:1 + $res = $req.GetResponse() + ~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException
打開在IE瀏覽器的url給我的答覆400壞請求。
這似乎與服務器上的IE配置文件有關,因爲服務器上的Chrome可以打開該URL。
有人會知道什麼reg鍵或設置在海洋中的選項,我需要改變,使這項工作?
感謝您閱讀我的問題。
[更新]
當嘗試運行它在我的憑據我仍然得到400錯誤,所以不要認爲這是因爲身份驗證:
$url = "http://server/ClearCache"
$req = [system.Net.WebRequest]::Create($url)
# $req.UseDefaultCredentials = $true
$passwd = ConvertTo-SecureString "password" -AsPlainText -Force;
$req.Credentials = New-Object System.Management.Automation.PSCredential ("myAccount", $passwd);
$res = $req.GetResponse()
$res