Android study notes excerpt (1) Retrofit2

1. Understand the common annotation interfaces for network access in Retrofit2. In fact, these interfaces are under the retrofit2.http package.

1. @GET GET network request method 
2, @POST POST network request method 
3, @Headers() header information parameter 
4, @Path() path parameter, replace the part enclosed by { } in the url address 
5, @Query() For query parameters, a string similar to "page = 1" will be appended to the url address to form the request parameters submitted to the server 
.  7.
@FormUrlEncoded 
encodes the content filled in the form field to avoid garbled  characters. 8. @Field
() specifies the name and corresponding value of each space in the form field. 
9. @FieldMap form field collection 
10. @Multipart Post submits a chunked request, if uploading a file, you must specify Multipart 

11. @Body Post submits a block request

2. Code steps:

1. Define an interface (encapsulate the URL address and data request) 
2. Instantiate Retrofit 
3. Create an interface service object through a Retrofit instance 
4. The interface service object calls the method in the interface to obtain the Call object 
5. The Call object executes the request (asynchronous, synchronous ask)

For details, refer to https://blog.csdn.net/baidu_31093133/article/details/51759452

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324823823&siteId=291194637