主要代码来源,参考文献:​​http://www.jianshu.com/p/bf884248cb37​

@GET("xx")

get请求


@Path

替换@GET(“a/{"id"}”)中的大括号

Call<RespnseBody> tt(@Path("id") int id);




@HTTP

万能请求方法

@HTTP(method = "get", path = "blog/{id}", hasBody = false)

method部分可替换为任何种类的请求

@Mutipart上传文件

//传单个文件
@Multipart
@POST("v1/create")
Call<ResponseBody> create(@Part("pictureName") RequestBody pictureName, @Part MultipartBody.Part picture

RequestBody pictureNameBody = RequestBody.create(MediaType.parse(AppConstants.CONTENT_TYPE_FILE), "pictureName");
File picture= new File(path);
RequestBody requestFile = RequestBody.create(MediaType.parse(AppConstants.CONTENT_TYPE_FILE), picture);
// MultipartBody.Part is used to send also the actual file name
MultipartBody.Part picturePart = MultipartBody.Part.createFormData("picture", picture.getName(), requestFile);
//调接口
create(pictureNameBody, picturePart);

//传多个文件
@Multipart
@POST("v1/create")
Call<ResponseBody> create(@Part("pictureName") RequestBody pictureName, @PartMap Map<String, RequestBody

RequestBody pictureNameBody = RequestBody.create(MediaType.parse(AppConstants.CONTENT_TYPE_FILE), "pictureName");
File picture= new File(path);
RequestBody requestFile = RequestBody.create(MediaType.parse(AppConstants.CONTENT_TYPE_FILE), picture);
Map<String, RequestBody> params = new HashMap<>();
params.put("picture\"; filename=\"" + picture.getName() + "", requestFile);
//调接口
create(pictureNameBody, params);


@Url

完整url

@GET
public void xx(@Url String url);


@FieldMap


@FieldMap Map<String, String> params

Post请求参数,使用@Post时,需要与

@FormUrlEncoded

连用,

同理,@Field("id") String id



@QueryMap,@Query("query")


用于get