Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Java

Idiom #174 Make HTTP POST request

Make a HTTP request with method POST to the URL u

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
String s = HttpClient.newHttpClient().send(HttpRequest.newBuilder()
                        .uri(URI.create(u))
                        .POST(HttpRequest.BodyPublishers.ofString(content))
                        .build(), HttpResponse.BodyHandlers.ofString())
                .body();
using System.Net.Http;
new HttpClient().PostAsync(u, content);

New implementation...
< >
programming-idioms.org