我试图调用GRPC端点,但我想提供客户身份验证标头.我在哪里指定这个? var client = new proto.Publisher('127.0.0.1:50051', grpc.credentials.createInsecure());var customHeader = { 'authorization': 'secret'}client.publi
var client = new proto.Publisher('127.0.0.1:50051', grpc.credentials.createInsecure()); var customHeader = { 'authorization': 'secret' } client.publish(data, function (err, response) { console.log('Sent'); });您需要创建一个grpc.Metadata对象,然后将其作为可选参数传递给该方法:
var client = new proto.Publisher('127.0.0.1:50051', grpc.credentials.createInsecure()); var metadata = new grpc.Metadata(); metadata.add('authorization', 'secret') client.publish(data, metadata, function (err, response) { console.log('Sent'); });