@@ -35,9 +35,20 @@ public class WatsonHttpClient : IClient
3535
3636 public MediaTypeFormatterCollection Formatters { get ; protected set ; }
3737
38+ public bool Insecure = false ;
39+
3840 public WatsonHttpClient ( string baseUri )
3941 {
40- this . BaseClient = new HttpClient ( ) ;
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+ }
4152 this . Filters = new List < IHttpFilter > { new ErrorFilter ( ) } ;
4253 if ( baseUri != null )
4354 this . BaseClient . BaseAddress = new Uri ( baseUri ) ;
@@ -47,21 +58,35 @@ public WatsonHttpClient(string baseUri)
4758
4859 public WatsonHttpClient ( string baseUri , string userName , string password )
4960 {
50- this . BaseClient = new HttpClient ( ) ;
51-
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+ }
5271 this . Filters = new List < IHttpFilter > { new ErrorFilter ( ) } ;
53-
5472 if ( baseUri != null )
5573 this . BaseClient . BaseAddress = new Uri ( baseUri ) ;
56-
5774 this . Formatters = new MediaTypeFormatterCollection ( ) ;
58-
5975 this . WithAuthentication ( userName , password ) ;
6076 }
6177
6278 public WatsonHttpClient ( string baseUri , string userName , string password , HttpClient client )
6379 {
64- this . BaseClient = client ;
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+ }
6590 this . Filters = new List < IHttpFilter > { new ErrorFilter ( ) } ;
6691 if ( baseUri != null )
6792 this . BaseClient . BaseAddress = new Uri ( baseUri ) ;
@@ -165,5 +190,10 @@ protected virtual void Dispose(bool isDisposing)
165190 {
166191 Dispose ( false ) ;
167192 }
193+
194+ public void SendAsInsecure ( bool insecure )
195+ {
196+ Insecure = insecure ;
197+ }
168198 }
169199}
0 commit comments