- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试通过 Powershell 3.0 和 REST API 使用我们的负载均衡器。但是,无论我尝试什么,如果它是 https 请求,无论是对我们的负载均衡器还是对任何其他 https 站点,我目前都遇到了失败。我觉得我错过了一些明显的东西。
这是 https 失败的代码
try
{
#fails
#$location='https://www.bing.com'
#fails
#$location='https://www.google.com'
#fails
#$location='https://www.facebook.com'
#fails
#$location='https://www.ebay.com'
#works
#$location='http://www.bing.com'
#works
#$location='http://www.google.com'
#fails (looks like Facebook does a redirect to https://)
$location='http://www.facebook.com'
#works
#$location='http://www.ebay.com'
$response=''
$response = Invoke-WebRequest -URI $location
$response.StatusCode
$response.Headers
}
catch
{
Write-Host StatusCode $response.StatusCode
Write-Host $_.Exception
}
System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.Management.Automation.PSInvalidOperationException:
There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspa
ce type. The script block you attempted to invoke was: $true
at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
--- End of inner exception stack trace ---
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
function Ignore-SSLCertificates
{
$Provider = New-Object Microsoft.CSharp.CSharpCodeProvider
$Compiler = $Provider.CreateCompiler()
$Params = New-Object System.CodeDom.Compiler.CompilerParameters
$Params.GenerateExecutable = $false
$Params.GenerateInMemory = $true
$Params.IncludeDebugInformation = $false
$Params.ReferencedAssemblies.Add("System.DLL") > $null
$TASource=@'
namespace Local.ToolkitExtensions.Net.CertificatePolicy
{
public class TrustAll : System.Net.ICertificatePolicy
{
public bool CheckValidationResult(System.Net.ServicePoint sp,System.Security.Cryptography.X509Certificates.X509Certificate cert, System.Net.WebRequest req, int problem)
{
return true;
}
}
}
'@
$TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)
$TAAssembly=$TAResults.CompiledAssembly
## We create an instance of TrustAll and attach it to the ServicePointManager
$TrustAll = $TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")
[System.Net.ServicePointManager]::CertificatePolicy = $TrustAll
}
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
最佳答案
这对我来说非常有效。该站点默认使用 TLS 1.0,显然 PS 无法使用。我使用了这一行:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
关于rest - Powershell 3.0 Invoke-WebRequest HTTPS 在所有请求上都失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25143946/
我正在查看 WebRequest.Create 之间的文档和 WebRequest.CreateHttp来决定我应该在我的应用程序中使用哪个。我没有看到这两种方法之间有什么不同,除了 WebReque
我想知道 DefaultWebProxy 和 GetSystemWebProxy() 之间的主要区别是什么。 MSDN 上有一些描述,但我仍然觉得我需要更多细节才能更好地理解。 此外,假设我在 C#
我想在 UI 上显示下载正在进行时下载文件。使用 WebRequest 我有两个选择: 使用 WebRequest.BeginGetResponse 和相关方法。 优点:可以以字节为单位显示准确的进度
我正在尝试注销对 MonoTouch 库的引用,所使用的是: IWebProxy oDefaultProxy = CFNetwork.GetDefaultProxy (); 在 .NET 中,还有
我首先发布了这个:HttpWebRequest: How to find a postal code at Canada Post through a WebRequest with x-www-fo
在 Windows PowerShell 3.0 中引入了 Invoke-RestMethod小命令。 Invoke-RestMethod cmdlet 接受 -Body用于设置请求正文的参数。 由于
我正在尝试在.bat文件中下载一个exe,但是无法隐藏输出 $progressPreference = 'silentlyContinue'| Out-Null 和$null 2>&1. 我不知道为什
我正在尝试 curl 包含分号的有效负载,但它失败了 Invoke-WebRequest -Uri $uri -Body '{"text" : "foo;"}' -Method Post Invoke
我有一个带有状态页面的网络设备,该页面可以通过Java小程序访问。使用Fiddler,我可以找到状态的http提要,但是页面会不断刷新。 (Firefox会显示该页面,但会保持刷新状态,Chrome会
有人可以向我解释为什么cUrl(真正的网址)有效但Invoke-WebRequest无效吗?同一台机器,相同变量。在我看来,他们俩都应该做同样的事情,将文件上传到jfrog Artifactory。
我正在尝试在 WebRequest 中发送表单数据。 该函数工作正常并按预期返回“成功”响应流。 但是,如果“data”变量的长度超过 30,000 个字符,我会遇到 HTTP 500 错误: Mes
我正在尝试在 WebRequest 中发送表单数据。 该函数工作正常并按预期返回“成功”响应流。 但是,如果“data”变量的长度超过 30,000 个字符,我会遇到 HTTP 500 错误: Mes
下面的代码需要怎么修改才能发送WebRequest通过指定的 proxy server和 port number ? Dim Request As HttpWebRequest = WebReques
我想执行一堆 WebRequest,但设置了可以同时启动的阈值。 我遇到了这个LimitedConcurrencyTaskScheduler example并尝试像这样使用它 scheduler =
我使用下面的代码在线检查一些pdf文件并相应地返回一个字符串。 问题是:当我添加第二个 Task.Factory.StartNew() 时,它开始复制所有请求,但仍然只返回一个答案(应该如此)。 我需
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(baseurl + url); req.Timeout = 1000 * 10;
我正在使用 WebRequest 执行简单请求,应用程序只是挂起,直到响应返回。我该如何解决这个问题? 看了很多题目,都说要用线程。我不知道如何使用它们;任何人都可以提供以下不挂起用户界面的示例吗?
以下代码在 WinForms 和 Windows Phone 8 应用程序中返回错误。 代码 var jsonData = "jsonStringGoesHere"; var uri
我正在用 C# 构建一个网络抓取工具,用于处理代理和大量请求。页面通过 ConnectionManager 类加载,该类获取代理并使用随机代理重试加载该页面,直到页面被正确加载。 平均一个任务需要10
我在做一个项目,多次调用一个网址 request = (HttpWebRequest)WebRequest.Create(url); request.GetResponse(); 这是我的代码。
我是一名优秀的程序员,十分优秀!