首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >grpc/grpc-js:在后端服务中从客户端接收的空请求

grpc/grpc-js:在后端服务中从客户端接收的空请求
EN

Stack Overflow用户
提问于 2021-12-27 09:13:42
回答 1查看 408关注 0票数 0

@grpc/grpc-js:^1.3.3 Node.js: v14.17.3

Client.js

代码语言:javascript
复制
client.updateBillingItems(request, function(err, response) {
            if (err) {
                res.send({error:'Server failed to update billing item'});
            }
            else {
                res.send(response);
            }
});

backend.js

代码语言:javascript
复制
PCServiceImpl.prototype.updateBillingItems = function updateBillingItems(call, callback) {
    var billingitems = call.request.billingitems; //Here the request received ( request: { billingitems: [] } ) is empty although data is passed from the client. Hence the susequent code fails to execute.
    console.log('updateBillingItems:', billingitems)
    es_query_obj.es_update_billing_items(billingitems)
    .then( results => {
        console.log('updateBillingItems:', JSON.stringify(results));
            callback(null, results);
    })
    .catch(err => {
        console.error("updateBillingItems: Caught ES exception:", err)
        callback(err)
    });
}  

请求:{记账项:[] } ->帐单项必须为如下数组

代码语言:javascript
复制
[{"chargemonth":"2021-12","dateofservice":"2021-12-20","geo":"LA"}]

因此,每当updateBillingItems()被client.js调用时,它尝试以数组的形式将更新后的数据发送到后端服务,但是后端服务接收的请求是空的,不确定原因。我的代码也使用proto,请求和响应格式都是按照proto定义的,但是这个调用仍然失败。

EN

回答 1

Stack Overflow用户

发布于 2022-06-06 06:58:07

事实证明,grpc-js json -> proto转换具有奇怪的命名约定。

考虑到以下主要问题:

代码语言:javascript
复制
message SomeMsg{
   string some_string_field = 1;
}

客户机和服务器impl将需要引用字段w/ camel的情况。

代码语言:javascript
复制
....
console.log(data.someStringField)
...
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70493588

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档