I am using DefaultHttpClient
to make requests in json from a Webservice, however this function is deprecated, what is the best alternative for creating a client for Webservice?
I am using DefaultHttpClient
to make requests in json from a Webservice, however this function is deprecated, what is the best alternative for creating a client for Webservice?
Utlize HttpClient. See the example below:
package com.hostingcompass.web.controller;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
public class WebCrawler {
public static void main(String[] args) throws Exception {
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet("http://mkyong.com");
HttpResponse response = client.execute(request);
//...
}
}
You do not need to close the connection.