zoukankan      html  css  js  c++  java
  • Grpc客户端添加请求头(Header)

           var metadata = new Metadata
                {
                    { "x-trace-id", $"123456789" }
                };
    
                var channel = GrpcChannel.ForAddress($"http://172.17.12.175:20026");
                // 开发环境请求地址var client = new UserAudioServiceClient(channel);
    
                var res = client.AddOrUpdateUserAudio(new Beta.VideoSettings.GrpcServer.AddOrUpdateReuest()
                {
                    AudioSynthesisId = "1",
                    BetaUnionId = 72057594038339269,
                    BusinessId = "180941",
                    ModuleId = 57006
                }, metadata); // 添加请求头
            public override async Task<UserAudioReply> GetUserAudio(UserAudioRequest request, ServerCallContext context)
            {
                var replay = new UserAudioReply()
                {
                    Status = StatusEnum.Success
                };
    
                try
                {
                    _logger.LogError("dddd");
                    var userAudio = await _userAudioQuery.GetUserAudioAsync(
                                                                    request.BetaUnionId,
                                                                    request.ModuleId,
                                                                    request.BusinessId);
    
                    replay.Data = _mapper.Map<UserAudioResult>(userAudio);
    
                }
                catch (System.Exception e)
                {
                    replay.Status = StatusEnum.Fail;
                    replay.Msg = "程序出错";
                    _logger.LogError("早报内容转音频出错 - GetUserAudio", e);
                }
    
                return replay;
            }
    ServerCallContext context中就可以看到添加的Header头


    可在拦截器中添加请求头,interceptor
  • 相关阅读:
    鼠标事件:
    各种坑记录
    Go学习笔记
    Scala学习笔记-7-代码片段
    Go学习笔记
    NIO学习笔记
    Redis常用操作
    docker & k8s 笔记
    Node常用笔记
    Maven常用笔记
  • 原文地址:https://www.cnblogs.com/yxzs/p/15744640.html
Copyright © 2011-2022 走看看