Add a Custom HTTP Header with the HttpClient
import org.apache.http.HttpResponse; import org.apache.http.HttpHeaders; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.methods.RequestBuilder; import org.apache.http.impl.client.BasicResponseHandler; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import java.io.IOException; public class Test { public static void main(String[] args) throws IOException { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { HttpUriRequest request = RequestBuilder.get() .setUri(“https://jsonplaceholder.typicode.com/todos/1”) // adding headers .setHeader(HttpHeaders.CONTENT_TYPE, “application/json”) .setHeader(“Authorization”, “Bearer 123token”) .build(); System.out.println(“Executing GET request…”); HttpResponse response = httpclient.execute(request);…
Read More Add a Custom HTTP Header with the HttpClient