Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

okhttp post

public void postJson() throws IOException {
    String json = "{"id":1,"name":"John"}";

    RequestBody body = RequestBody.create(
      MediaType.parse("application/json"), json);

    Request request = new Request.Builder()
      .url(BASE_URL + "/users/detail")
      .post(body)
      .build();
 
    Call call = client.newCall(request);
    Response response = call.execute();
}
Source by www.baeldung.com #
 
PREVIOUS NEXT
Tagged: #okhttp #post
ADD COMMENT
Topic
Name
9+5 =