gpt4 book ai didi

windows - TLS1.2 Powershell HttpWebClient 支持

转载 作者:可可西里 更新时间:2023-11-01 10:32:18 26 4
gpt4 key购买 nike

我正在尝试将文件上传到 https 端点,但我一直遇到:

Could not create SSL/TLS secure channel.

四处搜索,端点确实使用了 TLS 1.2 但在脚本中设置它似乎根本没有任何效果。有什么建议么?完整的脚本是:

#[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor "Tls12"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
#[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$uri = New-Object "System.Uri" "https://.../docs"
$request = [System.Net.HttpWebRequest]::Create($uri)
$request.Accept = "text/plain"
$request.UserAgent = "foo/2.3.0.0 (windows; x86_64)"
$request.ContentType = "application/x-tar"
$request.Headers.Add("Content-Encoding","gzip");
$request.Credentials = new-object System.Net.NetworkCredential("username","password","");

Try {
$request.Method = "PUT"
$requestStream = $request.GetRequestStream()
$fileStream = [System.IO.File]::OpenRead("R:\\...-docs.tar.gz")
$bufSize=10000
$chunk = New-Object byte[] $bufSize
while( $bytesRead = $fileStream.Read($chunk,0,$bufsize) )
{
$requestStream.write($chunk, 0, $bytesRead)
$requestStream.Flush()
}

$responseStream = $request.getresponse()
Write-Host "200";
Write-Host (-join [System.Text.Encoding]::UTF8.GetChars($bodyBytes));

} Catch [System.Net.WebException] {
$exception = $_.Exception;
If ($exception.Status -eq [System.Net.WebExceptionStatus]::ProtocolError) {
$response = $exception.Response -as [System.Net.HttpWebResponse];
$reader = new-object System.IO.StreamReader($response.GetResponseStream());
Write-Host ($response.StatusCode -as [int]);
Write-Host $reader.ReadToEnd();
} Else {
Write-Host $exception;
}
} Catch {
Write-Host $_.Exception;
} finally {
$fileStream.Close()
$requestStream.Close()
$responseStream.Close()

}

最佳答案

如果您的凭据不正确而不是 401 未经授权的响应,您会收到 Could not create SSL/TLS secure channel. 错误:(

关于windows - TLS1.2 Powershell HttpWebClient 支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49202109/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com