My WebApp needs to communicate with my server via ProtBuf. For this to be possible, I need to be able to post the raw binary data.
This is the code I'm using right now. The problem with this is that HttpClient encodes the Uint8Array as a JSON array, so that the result is not a valid protobuffer anymore:
const message = LoginRequest.fromObject({
code: code,
username: username,
password: password
});
const buffer: Uint8Array = LoginRequest.encode(message).finish();
this.http.post('https://api.myserver.com', buffer)
.subscribe(/*...*/);
HttpClient.post accepts some options, where you can set responseType to json, text, blob or arraybuffer. But this just sets the expected type of the response, the body of the request still gets encoded as JSON.
Does HttpClient have the possibility to send unencoded bodies?
Edit: This is the body I receive at the server:
{"0":10,"1":3,"2":97,"3":98,"4":99,"5":18,"6":5,"7":97,"8":100,"9":109,"10":105,"11":110,"12":26,"13":8,"14":112,"15":97,"16":115,"17":115,"18":119,"19":111,"20":114,"21":100}