- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
下面是我的自定义脚本扩展中的代码
$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
Invoke-WebRequest -Uri https://aka.ms/downloadazcopy-v10-windows -OutFile $env:C:\temp\azcopy.zip
当我运行自定义脚本扩展时,出现以下错误
"Invoke-WebRequest : The underlying connection was closed: An unexpected error
有什么解决办法吗?
最佳答案
该错误非常具体,这使得这可能是您的主机或企业环境中的环境问题,因为您发布的代码应该/确实可以按原样工作。
# Tested on a few lab hosts
$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
Invoke-WebRequest -Uri https://aka.ms/downloadazcopy-v10-windows -OutFile $env:C:\temp\azcopy.zip -Verbose
Get-ChildItem C:\temp
# Results
<#
VERBOSE: GET https://aka.ms/downloadazcopy-v10-windows with 0-byte payload
VERBOSE: received 9317519-byte response of content-type application/zip
Directory: C:\temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 9/11/2020 8:45 PM 9317519 azcopy.zip
#>
然而,您实际上只需要在代码顶部添加它。
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
您可以通过运行代码来了解有关错误的更多信息,让错误发生,然后使用
$Error[0] | Format-List -Force
您还可以使用 Trace-Command 了解更多信息cmdlet。
Trace-Command -Name metadata,parameterbinding,cmdlet -Expression {
Invoke-WebRequest -Uri https://aka.ms/downloadazcopy-v10-windows -OutFile $env:C:\temp\azcopy.zip
} -PSHost
# Results
<#
DEBUG: ParameterBinding Information: 0 : BIND NAMED cmd line args [Invoke-WebRequest]
DEBUG: ParameterBinding Information: 0 : BIND arg [https://aka.ms/downloadazcopy-v10-windows] to parameter [Uri]
DEBUG: ParameterBinding Information: 0 : COERCE arg to [System.Uri]
DEBUG: ParameterBinding Information: 0 : Trying to convert argument value from System.String to System.Uri
DEBUG: ParameterBinding Information: 0 : CONVERT arg type to param type using LanguagePrimitives.ConvertTo
DEBUG: ParameterBinding Information: 0 : CONVERT SUCCESSFUL using LanguagePrimitives.ConvertTo: [https://aka.ms/downloadazcopy-v10-windows]
DEBUG: ParameterBinding Information: 0 : Executing VALIDATION metadata: [System.Management.Automation.ValidateNotNullOrEmptyAttribute]
DEBUG: ParameterBinding Information: 0 : BIND arg [https://aka.ms/downloadazcopy-v10-windows] to param [Uri] SUCCESSFUL
DEBUG: ParameterBinding Information: 0 : BIND arg [\temp\azcopy.zip] to parameter [OutFile]
DEBUG: ParameterBinding Information: 0 : COERCE arg to [System.String]
DEBUG: ParameterBinding Information: 0 : Parameter and arg types the same, no coercion is needed.
DEBUG: ParameterBinding Information: 0 : BIND arg [\temp\azcopy.zip] to param [OutFile] SUCCESSFUL
DEBUG: ParameterBinding Information: 0 : BIND POSITIONAL cmd line args [Invoke-WebRequest]
DEBUG: ParameterBinding Information: 0 : MANDATORY PARAMETER CHECK on cmdlet [Invoke-WebRequest]
DEBUG: ParameterBinding Information: 0 : CALLING BeginProcessing
DEBUG: ParameterBinding Information: 0 : CALLING EndProcessing
#>
当尝试访问远程资源时,最好在采取行动之前测试事件/连接。通常这是 Test-Connection/Test-NetConection 的事情,但在您的情况下,Invoke-* cmdlet 之一会更谨慎。
Invoke-WebRequest -Uri 'https://aka.ms/downloadazcopy-v10-windows' -UseBasicParsing
# Results
<#
StatusCode : 200
StatusDescription : OK
Content : {80, 75, 3, 4...}
RawContent : HTTP/1.1 200 OK
Content-MD5: HjZjoPa87mg1bK4eVQqASQ==
x-ms-request-id: aa4341fb-e01e-00a6-0c94-810077000000
x-ms-version: 2009-09-19
x-ms-lease-status: unlocked
x-ms-blob-type: BlockBlob
Connect...
Headers : {[Content-MD5, HjZjoPa87mg1bK4eVQqASQ==], [x-ms-request-id, aa4341fb-e01e-00a6-0c94-810077000000], [x-ms-version, 2009-09-19],
[x-ms-lease-status, unlocked]...}
RawContentLength : 9317519
#>
另请参阅 article .
关于.net - “调用-WebRequest : The underlying connection was closed: An unexpected error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63855131/
我正在尝试使用 Invoke-WebRequest cmdlet(第一次)连接到 Sharp 打印机的 Web 界面。到目前为止,我的代码如下: $cred = Get-Credential $url
情况1: BufferedReader br = new BufferedReader( new InputStreamReader( new FileInputStream(file) ) ); b
我被要求关闭一个网站,因此在创建新网站时删除了文件并放置了一个带有“正在 build 中”消息的新索引页面。该站点的旧页面仍会显示在 google 中,但现在解析 403-Forbidden。 我希望
当使用带有反射的路径相关类型时,即使我有匹配的“底层类型”,我也会收到类型不匹配错误。这些“非底层类型”是什么?为什么检查它们而不是“底层类型”? 在下面的代码中,我希望 compare 方法仅接受
我对在这个网站上提问非常陌生,但通过阅读它学到了很多东西,所以非常感谢! 有点随机,看到了这个页脚上这种令人敬畏的“地毯下”风格的视差效果 - 并寻找一些关于如何将其提升的提示? http://ide
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我正在尝试使用来自 google guava 库的 AbstractScheduledService。在 the docs for this class我看到以下内容: The executor wi
我有一个 enum其中每个成员都是 Set ,即以下是我的代码: // Guava used only for the ease of "Sets.newHashSet(E... elements)"
我的应用程序必须下载一个文件,here is the url .该应用程序多年来一直运行良好,但在供应商方面最近发生变化后,我收到“基础连接已关闭:发送时发生意外错误。” 我已经阅读了网上的所有相关信
我已经看到很多关于这个主题的话题......但是谷歌上的解决方案对我不起作用。 我正在使用 HttpWebRequest 对象执行 POST 操作,当我尝试发布大量数据时出现错误 The underl
了解 STL 容器实际情况的最佳方式是什么?我认为仅仅编程是不够的。有专门针对这个的书籍吗? 最佳答案 这本书非常好,即使它可能没有像您希望的那样深入到细节:The C++ Standard Libr
这是场景:我有一个按钮 B,还有一个滑动抽屉,拉出时会覆盖整个屏幕。当我拉出屏幕并触摸 B 曾经可见的屏幕时,它的 Action 仍在执行。 我该如何解决这个问题? 我找到了 this线程描述了同样的
我正在尝试解析 PDF 并创建某种层次结构。考虑输入 Title 1 some text some text some text some text some text some text some
perl 中的基本类型与大多数语言不同,类型为标量、数组、哈希(但显然不是子例程,&,我猜这实际上只是带有语法糖的标量引用)。最奇怪的是,最常见的数据类型:int、boolean、char、strin
在生产中,我的应用程序开始出现此错误: The underlying provider failed on Open 据我所知,在本地测试应用程序时我没有收到此错误(至少无论我做什么都无法得到它)。我
我遇到了一个在将 Entity Framemork 与 MySQL 连接器一起使用之前从未遇到过的问题。我有下面的简单方法核心: ps_manufacturer manufacturer = null
我在我的程序中使用 websocketpp 作为 websocket 服务器。但是最近在某些用户的环境中,当我监听某个特定端口时,发生了错误,我打印了 error_code 消息,它是“Underly
我有一个黑色的导航栏 (bar) 和一个垂直的白色页面 (page)。 页面 应该从下到下运行,看起来就像刚从栏 的正下方出来一样。 bar 有一个投影,它显然应该在 page 上 - 如下所示: 问
我在 C++11 中工作,包括一个在 C++03 中实现的 h 文件。在我包含的 h 文件中,定义了一个枚举 Foo。我想在 code.h 中声明一个转发到它并在 code.cpp 中使用它: 标题.
我正在学习 Go(到目前为止很喜欢),但我遇到了一个有趣的问题。编译失败的代码是: package main import "fmt" type MyInt int func (i MyInt) Do
我是一名优秀的程序员,十分优秀!