vue3+ts环境中,项目中需要引入gRPC来与后端进行通信,现通过sayHello方法获取到的response是null,接口有正常响应。
import { GreeterClient } from "../../protos/generateCode/test/greet_pb_service";
import { v1 } from "../../protos/generateCode/test/greet_pb.js"
import { grpc } from "@improbable-eng/grpc-web";
const client = new GreeterClient('https://localhost:49641');
const grpcRequest = new v1.HelloRequest();
var headerRequest = new grpc.Metadata();
headerRequest.set("Content-Type", "application/grpc-web-text");
headerRequest.set("Authority", localStorage.getItem("accessToken"));
headerRequest.set("accept", "application/grpc-web-text");
grpcRequest.setName("张三");
client.sayHello(grpcRequest, headerRequest, (err, response) => {
console.log(err, response) // null, null
});
有小伙伴可以帮忙远程解决吗,远程协助解决有红包
greet_pb_service、greet_pb.js文件是通过ts-protoc-gen编译生成的