2015-11-10 13 views
1

取得的工作原理:.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 

回答

0

不知道是什麼問題是或爲什麼它在Chrome中工作,但不是IE。由於響應主體(當您按F12時可以在IE devtools中看到響應主體)說「無效的主機名」,我試圖在C:\Windows\System32\drivers\etc\hosts(如127.0.0.1 myserver)中添加一些DNS綁定,並取消註釋localhost但沒有結果。

最後用ip地址代替服務器名稱和解決它(XXX是IP地址數):

$url = "http://xxx.xxx.xxx.xxx/ClearCache" 
相關問題