Retrofit transmits data that is not json in the body
Retrofit transfer Json data method
@POST("robot/send")
SendTextResponse sendMsg(@Query("access_token") String accessToken, @Body SendTextRequest request);
Just use the @Body annotation, and Retrofit will use FastJson for serialization.
But sometimes it is necessary to transmit encrypted content, for example:
@Body String request
If it is transmitted in this way, the String string will still be converted to json, which will lead to data errors.
Solution
import okhttp3.RequestBody;
@POST("openapi/api/xxx")
Response dispatch(@HeaderMap Map<String, String> headerMap, @Body RequestBody request)
Caller:
api.dispatch(headerMap, RequestBody.create(MediaType.get("application/json"), request));
It can be solved perfectly! ! !
There are many serialization methods in Retrofit, and the specific source code has not yet been seen. If you have a familiar partner, you can comment and point it out!