programing

승인되지 않은 단순 Rest 쿼리를 실행하는 동안 예기치 않은 오류가 발생했습니다.

linuxpc 2023. 8. 14. 22:33
반응형

승인되지 않은 단순 Rest 쿼리를 실행하는 동안 예기치 않은 오류가 발생했습니다.

인증 확인을 수행하지 않는 나머지 끝점이 있습니다.Linux에서 간단한 컬 명령을 실행할 수 있습니다.

curl -k https://application/api/about

이렇게 하면 응답합니다.

그러나 PowerShell에서 다음을 시도하면 실패합니다.

Invoke-RestMethod https://application/api/about

그러면 다음과 같은 것을 알 수 있습니다.

Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send.
At line:1 char:1
+ Invoke-RestMethod $Application
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

누가 제게 이 문제를 어떻게 해결할 수 있는지 알려주실 수 있나요?

편집:

Invoke-WebRequest를 사용하는 중:

Invoke-WebRequest -Uri "https://application/api/about"

Invoke-WebRequest : 기본 연결이 닫혔습니다.전송에서 예기치 않은 오류가 발생했습니다.line:1 char:1 + Invoke-WebRequest -우리 "https://application/api/a ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~정보: 잘못된 작업: (시스템).Net.HttpWeb 요청:HttpWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdlet WebResponseException, Microsoft.PowerShell.명령.웹 요청 명령 호출

사용:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Take from Powershell 3.0 Invoke-WebRequest HTTPS가 모든 요청에서 실패합니다.

제 경우 TLS 트릭이 작동하지 않았습니다. 파워셸의 버그인 것 같습니다.스크립트 블록 대신 .net 코드를 사용하여 콜백을 추가해야 합니다.

#C# class to create callback
$code = @"
public class SSLHandler
{
    public static System.Net.Security.RemoteCertificateValidationCallback GetSSLHandler()
    {

        return new System.Net.Security.RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return true; });
    }

}
"@

#compile the class
Add-Type -TypeDefinition $code

#disable checks using new class
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = [SSLHandler]::GetSSLHandler()
#do the request
try
{
    invoke-WebRequest -Uri myurl -UseBasicParsing
} catch {
    # do something
} finally {
   #enable checks again
   [System.Net.ServicePointManager]::ServerCertificateValidationCallback = $null
}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12

Windows Server 2016에서 작동합니다.

주 보조 빌드 개정


5 1 17763 1007

언급URL : https://stackoverflow.com/questions/41897114/unexpected-error-occurred-running-a-simple-unauthorized-rest-query

반응형