APACHE HTTPCOMPONENTS / CATATAN</>↗Apache HttpComponents11 Jan 2017
This example demonstrates how to do multipart upload using the Apache HttpClient library. In this example we upload a single file. We start by creating an object of the file to be uploaded. The FileBody represent the binary body part of the file. Next, prepare the HttpEntity object by create an instance of MultipartEntityBuilder. Add […]
APACHE HTTPCOMPONENTS / CATATAN</>↗Apache HttpComponents06 Jan 2017
The following code snippet show you how to send POST request with a JSON body using HttpClient. The payload in this example is a user information containing id, first_name and a last_name. We placed the payload in an object called StringEntity and also set its content type to ContentType.APPLICATION_FORM_URLENCODED. On the other end called by […]
APACHE HTTPCOMPONENTS / CATATAN</>↗Apache HttpComponents27 Nov 2012
The following code snippet will show you how to send an HTTP post request using the Apache HttpComponents. We will send a post request to https://httpbin.org/post, with some parameters to the request using the NameValuePair object. To pass these parameters to the HTTP post request we create an instance of UrlEncodedFormEntity and pass a list […]
APACHE HTTPCOMPONENTS / CATATAN</>↗Apache HttpComponents26 Nov 2012
This example show you how to get HTTP response body as a string when using the Apache HttpComponents library. To get the response body as a string we can use the EntityUtils.toString() method. This method read the content of an HttpEntity object content and return it as a string. The content will be converted using […]
APACHE HTTPCOMPONENTS / CATATAN</>↗Apache HttpComponents26 Nov 2012
This code snippet show you how to get the content-type of an HTTP Get request. The ContentType can be obtained by using ContentType.getOrDefault() method and passing an HttpEntity as the argument. The HttpEntity can be obtained from the HttpResponse object. From the ContentType object we can get the mime-type by calling the getMimeType() method. This […]
APACHE HTTPCOMPONENTS / CATATAN</>↗Apache HttpComponents26 Nov 2012
Below is an example using HttpClient library to retrieve the response of HTTP GET request. We start by creating an instance of CloseableHttpClient class. We then define an HTTP GET request by create an instance of HttpGet class and specify the Url of a website we are going to retrieve. To execute the request we […]