@@ -1326,23 +1326,41 @@ public static bool BuildDeployUploadArtifacts()
1326
1326
{
1327
1327
string fileName = Path . GetFileName ( sourceFile ) ;
1328
1328
1329
- using ( HttpClient client = new HttpClient ( ) )
1330
- using ( FileStream fileStream = File . OpenRead ( sourceFile ) )
1331
- using ( StreamContent streamContent = new StreamContent ( fileStream ) )
1332
- using ( MultipartFormDataContent content = new MultipartFormDataContent ( ) )
1329
+ using ( HttpClientHandler httpClientHandler = new HttpClientHandler ( ) )
1333
1330
{
1334
- client . DefaultRequestHeaders . Add ( "X-ApiKey" , buildBuildUrlKey ) ;
1335
- streamContent . Headers . Add ( "Content-Type" , "application/octet-stream" ) ;
1336
- streamContent . Headers . Add ( "Content-Disposition" , "form-data; name=\" file\" ; filename=\" " + fileName + "\" " ) ;
1337
- content . Add ( streamContent , "file" , fileName ) ;
1331
+ httpClientHandler . AutomaticDecompression = DecompressionMethods . All ;
1332
+ httpClientHandler . ServerCertificateCustomValidationCallback = ( message , cert , chain , sslPolicyErrors ) =>
1333
+ {
1334
+ // Allow this client to communicate with authenticated servers.
1335
+ if ( sslPolicyErrors == System . Net . Security . SslPolicyErrors . None )
1336
+ return true ;
1338
1337
1339
- var httpTask = client . PostAsync ( buildBuildUrl , content ) ;
1340
- httpTask . Wait ( ) ;
1338
+ // Temporarily ignore wj32.org expired certificate.
1339
+ if ( string . Equals ( cert . GetCertHashString ( ) , "b60cb3b6aac5f59075689fc3c7dfd561750ce100" , StringComparison . OrdinalIgnoreCase ) )
1340
+ return true ;
1341
1341
1342
- if ( ! httpTask . Result . IsSuccessStatusCode )
1343
- {
1344
- Program . PrintColorMessage ( "[HttpClient PostAsync] " + httpTask . Result , ConsoleColor . Red ) ;
1342
+ // Do not allow this client to communicate with unauthenticated servers.
1345
1343
return false ;
1344
+ } ;
1345
+
1346
+ using ( HttpClient client = new HttpClient ( httpClientHandler ) )
1347
+ using ( FileStream fileStream = File . OpenRead ( sourceFile ) )
1348
+ using ( StreamContent streamContent = new StreamContent ( fileStream ) )
1349
+ using ( MultipartFormDataContent content = new MultipartFormDataContent ( ) )
1350
+ {
1351
+ client . DefaultRequestHeaders . Add ( "X-ApiKey" , buildBuildUrlKey ) ;
1352
+ streamContent . Headers . Add ( "Content-Type" , "application/octet-stream" ) ;
1353
+ streamContent . Headers . Add ( "Content-Disposition" , "form-data; name=\" file\" ; filename=\" " + fileName + "\" " ) ;
1354
+ content . Add ( streamContent , "file" , fileName ) ;
1355
+
1356
+ var httpTask = client . PostAsync ( buildBuildUrl , content ) ;
1357
+ httpTask . Wait ( ) ;
1358
+
1359
+ if ( ! httpTask . Result . IsSuccessStatusCode )
1360
+ {
1361
+ Program . PrintColorMessage ( "[HttpClient PostAsync] " + httpTask . Result , ConsoleColor . Red ) ;
1362
+ return false ;
1363
+ }
1346
1364
}
1347
1365
}
1348
1366
}
0 commit comments