티스토리 뷰

반응형

HttpClient를 이용해서 https://ipfs.io/ipfs/를 호출하는데 안드로이드에서 해당 오류가 발생합니다.

아래 내용을 참고해서 수정했습니다.

 

참고

A call to SSPI failed SSL routines:OPENSSL s with Android 5.0 and lower versions (microsoft.com)

 

A call to SSPI failed SSL routines:OPENSSL s with Android 5.0 and lower versions

User380049 posted Or add it like this public async Task GetClient() { HttpClientHandler handler = new HttpClientHandler(); handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true; HttpClient client = new HttpClient(handle

social.msdn.microsoft.com

해결 방법은 HttpClientHandler를 추가해서 ServerCertificateCustomValidationCallback 프로퍼티를 아래와 같이 구현하고 사용하는 것입니다.

            //HttpClientHandler를 추가해서 해결
            HttpClientHandler handler = new HttpClientHandler
            {
                ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true
            };

            using (var httpClient = new HttpClient(handler))
            {
                try
                {
                    var url = "https://ipfs.io/ipfs/" + ipfsHash;
                    httpClient.Timeout = new TimeSpan(0, 5, 0);
                    var response = await httpClient.GetAsync(url);
                    response.EnsureSuccessStatusCode();
                    var fileString = await response.Content.ReadAsStringAsync();
                    return fileString;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
                return null;
            }

 

반응형
댓글