我正在使用spring框架反应式webclient进行如下调用
webClient.post()
.uri("/v/score/$model")
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(gson.toJson(request))
.accept(MediaType.APPLICATION_JSON)
.header("Client-Id", clientId)
.awaitExchange()
.awaitBody<ScoringResponse>()
运行得很好。现在,我希望将请求作为协议缓冲区对象传递,而不是作为json。我该怎么做呢?
发布于 2020-02-20 11:40:11
将媒体类型设置为application/octet-stream
,并使用.toByteArray()
方法以字节数组的形式传递原型模型。在接收端,您可以使用静态方法{proto generated class}.parseFrom({your bytes come here})
来重新构建proto对象。
不要忘记POST方法请求基本上是一个主体内容;)
https://stackoverflow.com/questions/60279890
复制相似问题