Http Basic Authentication in Java using HttpClient?

0 votes
Is there any httpclient command used for Http basic Authentication?
Dec 20, 2018 in Java by Sushmita
• 6,880 points
106 views

1 answer to this question.

0 votes
String encoding = Base64Encoder.encode ("test1:test1");
HttpPost httppost = new HttpPost("http://host:post/test/login");
httppost.setHeader("Authorization", "Basic " + encoding);

System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
answered Dec 20, 2018 by Daisy
• 8,050 points

Related Questions In Java

0 votes
1 answer

Simple HTTP server in Java using only Java SE API

You can write a pretty simple embedded Jetty Java ...READ MORE

answered Aug 28, 2018 in Java by parth295
• 4,640 points
324 views
0 votes
2 answers

How can I create File and write data in it using Java?

import java.io.BufferedWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public class WriteFiles{ ...READ MORE

answered Jul 26, 2018 in Java by samarth295
• 2,190 points
133 views
0 votes
2 answers
0 votes
2 answers

Fetch list of in-between dates using Java

java.time Package The new java.time.package in Java 8 incorporates ...READ MORE

answered Aug 21 in Java by Sirajul
• 40,990 points
176 views
0 votes
2 answers

Send HTTP request in Java

import com.google.api.client.http.GenericUrl; import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpResponse; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; import java.io.IOException; import ...READ MORE

answered Aug 3, 2018 in Java by samarth295
• 2,190 points
179 views
0 votes
1 answer

How to encode the HTTP URL address in Java?

Use one of the constructors with more ...READ MORE

answered Oct 23, 2018 in Java by Sushmita
• 6,880 points
85 views
+5 votes
3 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,380 points

edited Nov 6, 2018 by Omkar 11,310 views
0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,110 points
2,420 views
0 votes
1 answer

simple HTTP server in Java using only Java SE API

The com.sun.net.httpserver solution is not portable across JREs. Its ...READ MORE

answered Jan 4 in Java by Daisy
• 8,050 points
501 views
+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,190 points
705 views