如何在Postman脚本中将请求体从JSON更改为Protobuf

g2ieeal7  于 7个月前  发布在  Postman
关注(0)|答案(1)|浏览(78)

如何在Postman脚本中将请求体更改为protobuf?
我正在测试一个API端点,它以protobuf msg作为主体,
在Golang中,我会做这样的事情,

protodata, err = proto.Marshal(&protoStruct)

字符串
将输入的json字符串转换为编组的proto消息并将其与请求一起发布。我试图使用脚本在postman中执行此操作,但导入protobuf包时出错
评估预请求脚本时出错:语法错误:无法在模块外部使用导入语句

import { Protobuf } from 'google-protobuf';

const message = new Protobuf.Message();
message.set('msg', '{"command_code": "test_check"}');

const serialized = message.serialize();
pm.environment.set('request_body', serialized);


输入的JSON只是
{“command_code”:“test_check”}
在go代码执行后,我通常从json中获取格式为
“0A086669656C6431120676616C756531”
为了发布到请求URL,我试图用Postman做同样的事情,这样我就可以在那里测试它
我做错了吗,postman中是否有内置的支持马歇尔json到protobuf?我甚至尝试在golang中打印出二进制文件,然后尝试将其用作postman的输入,但二进制文件只是它的表示,这就是为什么我想到在postman中生成它
[10 184 1 10 123 10 32 32 34 102 ]

wgmfuz8q

wgmfuz8q1#

我可以回答你的部分问题。
Postman Sandbox仅支持某些库。
https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#using-external-libraries
但是,你不能发送一个普通的grpc请求吗?
https://blog.postman.com/postman-now-supports-grpc/

相关问题