Ignore bad certificate - .NET CORE

前端 未结 4 426
没有蜡笔的小新
没有蜡笔的小新 2020-12-30 02:44

I\'m writing a .NET Core app to poll a remote server and transfer data as it appears. This is working perfectly in PHP because the PHP is ignoring the certificate (which is

4条回答
  •  悲&欢浪女
    2020-12-30 03:46

    //at startup configure services add the following code

    services.AddHttpClient(settings.HttpClientName, client => {
    // code to configure headers etc..
    }).ConfigurePrimaryHttpMessageHandler(() => {
                      var handler = new HttpClientHandler();
                      if (hostingEnvironment.IsDevelopment())
                      {
                          handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; };
                      }
                      return handler;
                  });
    

    now you can use IHttpClientFactory CreateClient method within your service

提交回复
热议问题