March 2019
Intermediate to advanced
242 pages
6h 21m
English
Imagine that you want to post the details of a form to a web application or web service programmatically. You can do so by sending a POST request, using the HTTP Client API. The following code uses the send() method from HttpClient to post a set of parameter names and values to a server. The parameter names and their values are stored as a String value:
public class HttpReqPost {
public static void main(String uri[]) throws Exception {
String postData = "? name='Mala'&email='info@ejavaguru @gmail.com'"; HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("http://www.ejavaguru.com/Java11/register.php")) .POST(BodyPublishers.ofString(postData)) .build(); HttpResponse<?> ...Read now
Unlock full access