2016-11-09 627 views
3

我已經提供了一個新的Server 2012框進行設置。使用powershell連接到HTTPS站點

我試圖使用PowerShell安裝的巧克力

iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

,並得到錯誤

Exception calling "DownloadString" with "1" argument(s): "The underlying connection was closed: An unexpected error occurred on a receive." At line:1 char:1 + iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/in ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException

我可以在瀏覽器中訪問that URL

起初我還以爲這是什麼做的巧克力,但後來我意識到,

(New-Object System.Net.WebClient).DownloadString('http://google.com'))

可以下載HTML內容

((New-Object System.Net.WebClient).DownloadString('https://google.com'))

失敗相同的錯誤

The underlying connection was closed: An unexpected error occurred on a receive.

盒:

  • 是Windows Server 2012中構建9600
  • 不使用代理
  • 已防火牆關閉

我確信我米做一些愚蠢的事,但看不到什麼...

---更新---

基於this answer

我按照這些步驟:

``` 1.In控制面板,單擊管理工具,然後雙擊本地安全策略。

2.在本地安全設置中,展開本地策略,然後單擊安全選項。

3.在右窗格中的策略下,雙擊系統加密:使用FIPS兼容算法進行加密,散列和簽名,然後單擊啓用。

  • 冉運行gpupdate/force ```
  • ,所述的巧克力後安裝腳本可被下載但隨後失敗:

    STDOUT: FIPS Mode detected - run 'choco feature enable -n useFipsCompliantChecksums' to use Chocolatey. When FIPS Mode is enabled, Chocolatey requires useFipsCompliantChecksums feature also be enabled. STDERR: ---- End output of C:\ProgramData\chocolatey/bin/choco.exe list -l -r ---- Ran C:\ProgramData\chocolatey/bin/choco.exe list -l -r returned 1

    仍然覺得不應該有必要改變GPO

    +0

    嘗試在下載內容之前執行以下操作:'[System.Net.ServicePointManager] :: ServerCertificateValidationCallback = {$ true}' –

    +0

    可以在命令中依次運行行?如果是這樣,則不起作用。但也是否會關閉證書驗證?這感覺有點危險 –

    +1

    是的,這會關閉證書驗證。例如,如果您使用自簽名證書並且不想將其安裝在所有客戶端上,那麼這很有用。 G。測試目的。但是,這可能不是你的問題 –

    回答

    4

    事實證明,這是因爲我們的服務器映像中禁用了TLS 1.0以符合PCI DSS 3.1。

    將更改回滾到映像解決了powershell問題。

    在短期內,我們可以運行

    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12使用System.Net.WebClient之前,但我想找到一種方法來執行,在一臺機器的水平太...


    logged this with Chocolatey,他們解決了問題\ o/

    0

    試試這個:

    $WBC = New-Object System.Net.WebClient 
    
    $WBC.DownloadString("https://google.com") 
    
    +1

    這只是相同的命令分佈在兩行。不會以這種方式工作 –

    +0

    儘管此代碼片段可能會解決問題,包括解釋[真的有幫助](// meta.stackexchange.com/q/114762)以提高帖子的質量。請記住,你正在爲將來的讀者回答這個問題,而不僅僅是現在問的人!請編輯您的答案以添加解釋,並指出適用的限制和假設。 –