How to send byte[] array in retrofit

后端 未结 2 1349
半阙折子戏
半阙折子戏 2020-12-16 21:09

How do you send byte[] array in retrofit call. I just need to send over byte[]. I get this exception when I have been trying to send a retrofit call.

ret

2条回答
  •  执念已碎
    2020-12-16 22:03

    For retrofit2:

    @POST("/send")
    void upload(@Body RequestBody bytes, Callback cb);
    

    usage:

    byte[] params = ...
    RequestBody body = RequestBody.create(MediaType.parse("application/octet-stream"), params);
    remoteService.upload(body, new Callback() {
        @Override
        public void success(String s, Response response) {
            //Success Handling
        }
    
        @Override
        public void failure(RetrofitError retrofitError) {
            //Error Handling
        }
    }); 
    

提交回复
热议问题