2016-01-02 8 views

Antwort

5

Sie können senden Parameter senden, senden die Parameter als JSON-Objekt geschätzt werden sollte. wie:

@POST("user/checkloc") 
Call<CheckLocation> checkLocation(@Body Location location); 

Hier Lage ist pojo Objekt wie:

public class Location { 
String lat,lng; 

    public Location(String lat, String lng) { 
     this.lat = lat; 
     this.lng = lng; 
    } 
} 

und es wird Parameter als JSON-Objekt senden, wie:

D/OkHttp﹕ --> POST /api/index.php/user/checkloc HTTP/1.1 
D/OkHttp﹕ {"lat":"28.4792293","lng":"77.043042"} 

Sie auch Parameter wie HashMap schicken:

@POST("user/checkloc") 
Call<CheckLocation> checkLocation(@Body HashMap<String, String> hashMap); 
+0

Vielen Dank für Ihren Kommentar. Kann ich andere Parameter zusammen mit Body senden? Zum Beispiel URL, Header zusammen mit Body. –

+0

checkLocation (@Header ("Authorization") Zeichenfolge Token, @Body Location location); –