wangfengqi688
wangfengqi688
Hello all: You need to merge CRT and key into PFX,like this: openssl pkcs12 -export -in client.crt -inkey client.key -out client.pfx and: Invoke WithTls method input allowUntrustedCertificates = true
var options = new MqttClientOptionsBuilder() .WithClientId(clientID) .WithTcpServer("192.168.8.4", 8883) .WithCredentials("mqttuser", "wfq123") .WithKeepAlivePeriod(new TimeSpan(0, 0, 0, 40)) //.WithWillMessage(message) .WithTls(true, false, false, File.ReadAllBytes(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ssl", "ca.crt")), File.ReadAllBytes(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ssl", "client.pfx"))) //.WithCleanSession() .WithProtocolVersion(MQTTnet.Serializer.MqttProtocolVersion.V311) .Build(); await mqttClient.ConnectAsync(options);