I'm trying to send a protobuf over http post to java spring server from node js client.
message.serializeBinary()
gives me a uint8 bytes array which I tried to encode with new StringDecoder('utf8').write(<bytes>)
. And I send it over post with npm request-promise:
const request = require('request-promise')
const options = {
uri: <some url>,
method: 'POST',
qs: {
'attr1': 'value1',
'attr2': new StringDecoder('utf8').write(message.serializeBinary())
}
}
request(options).then(console.log).catch(console.log)
This hits spring server endpoint
@ResponseBody String endpoint(@RequestParam String attr1, @RequestParam String attr2) {
// This is raising InvalidProtocolBufferException
var message = Message.parseFrom(attr2.getBytes(StandardCharsets.UTF_8));
}
Looks like encoding issue to me, I'm not sure what encoding to use to transport a protocol buffer over http. Or If i'm doing something else wrong, please point it out too.