编码表单和分段数据

方法也可以被声明为发送编码表单和分段数据.

当使用@FormUrlEncoded注解方法时, 则为发送编码表单数据. 每个键值对使用@Field注解, 并在其中带有名称和提供值的对象.

@FormUrlEncoded
@POST("user/edit")
Call<User> updateUser(@Field("first_name") String first, @Field("last_name") String last);

当使用@Multipart注解方法时, 则为分段请求. 每段数据使用@Part注解来声明.

@Multipart
@PUT("user/photo")
Call<User> updateUser(@Part("photo") RequestBody photo, @Part("description") RequestBody description);

分段数据需要使用Retrofit中的某个转化器, 或者通过实现RequestBody来处理分段数据的序列化.