代码拉取完成,页面将自动刷新
用于指定请求体类型的注解@BodyType
,可用于发送请求体格式与ContentType相异的数据
/**
* 此请求Content-Type头为 x-www-form-urlencoded
* 而请求体的格式却可以是JSON格式
*/
@BodyType("json")
@Post(url = "/", contentType = ContentType.APPLICATION_X_WWW_FORM_URLENCODED)
String send(@Body("name") String name, @Body("value") Object value);
@BodyType
注解同时可以指定Encoder
/**
* 指定请求体格式为json的同时,指定Encoder为Jackson转换器
*/
@BodyType(type = "json", encoder = ForestJacksonConverter.class)
@Post(url = "/", contentType = ContentType.APPLICATION_X_WWW_FORM_URLENCODED)
String send(@Body Entry entry);
如果要指定特定JSON转换器为某一请求的Encoder,可以使用对应JSON框架的快捷注解
/**
* 指定Fastjson为Encoder
*/
@FastjsonEncoder
@Post("/")
String sendFastjson(@Body Entry entry);
/**
* 指定Jackson为Encoder
*/
@JacksonEncoder
@Post("/")
String sendJackson(@Body Entry entry);
/**
* 指定Gson为Encoder
*/
@GsonEncoder
@Post("/")
String sendGson(@Body Entry entry);