@@ -39,16 +39,7 @@ public class WatsonHttpClient : IClient
3939
4040 public WatsonHttpClient ( string baseUri )
4141 {
42- if ( Insecure )
43- {
44- var httpClientHandler = new HttpClientHandler ( ) ;
45- httpClientHandler . ServerCertificateCustomValidationCallback = ( message , cert , chain , errors ) => { return true ; } ;
46- this . BaseClient = new HttpClient ( httpClientHandler ) ;
47- }
48- else
49- {
50- this . BaseClient = new HttpClient ( ) ;
51- }
42+ this . BaseClient = new HttpClient ( ) ;
5243 this . Filters = new List < IHttpFilter > { new ErrorFilter ( ) } ;
5344 if ( baseUri != null )
5445 this . BaseClient . BaseAddress = new Uri ( baseUri ) ;
@@ -58,16 +49,7 @@ public WatsonHttpClient(string baseUri)
5849
5950 public WatsonHttpClient ( string baseUri , string userName , string password )
6051 {
61- if ( Insecure )
62- {
63- var httpClientHandler = new HttpClientHandler ( ) ;
64- httpClientHandler . ServerCertificateCustomValidationCallback = ( message , cert , chain , errors ) => { return true ; } ;
65- this . BaseClient = new HttpClient ( httpClientHandler ) ;
66- }
67- else
68- {
69- this . BaseClient = new HttpClient ( ) ;
70- }
52+ this . BaseClient = new HttpClient ( ) ;
7153 this . Filters = new List < IHttpFilter > { new ErrorFilter ( ) } ;
7254 if ( baseUri != null )
7355 this . BaseClient . BaseAddress = new Uri ( baseUri ) ;
@@ -77,16 +59,7 @@ public WatsonHttpClient(string baseUri, string userName, string password)
7759
7860 public WatsonHttpClient ( string baseUri , string userName , string password , HttpClient client )
7961 {
80- if ( Insecure )
81- {
82- var httpClientHandler = new HttpClientHandler ( ) ;
83- httpClientHandler . ServerCertificateCustomValidationCallback = ( message , cert , chain , errors ) => { return true ; } ;
84- this . BaseClient = new HttpClient ( httpClientHandler ) ;
85- }
86- else
87- {
88- this . BaseClient = new HttpClient ( ) ;
89- }
62+ this . BaseClient = new HttpClient ( ) ;
9063 this . Filters = new List < IHttpFilter > { new ErrorFilter ( ) } ;
9164 if ( baseUri != null )
9265 this . BaseClient . BaseAddress = new Uri ( baseUri ) ;
@@ -193,7 +166,18 @@ protected virtual void Dispose(bool isDisposing)
193166
194167 public void SendAsInsecure ( bool insecure )
195168 {
196- Insecure = insecure ;
169+ if ( insecure )
170+ {
171+ var httpClientHandler = new HttpClientHandler ( ) ;
172+ httpClientHandler . ServerCertificateCustomValidationCallback = ( message , cert , chain , errors ) => { return true ; } ;
173+ this . BaseClient = new HttpClient ( httpClientHandler ) ;
174+ }
175+ else
176+ {
177+ var httpClientHandler = new HttpClientHandler ( ) ;
178+ httpClientHandler . ServerCertificateCustomValidationCallback = null ;
179+ this . BaseClient = new HttpClient ( httpClientHandler ) ;
180+ }
197181 }
198182 }
199183}
0 commit comments