Reputation: 791
I want to pass these parameters with a HTTP request to a WebApp hosted in Tomcat Container, User Name, Password, The resource this request queries, What type a request is send
So is there a way to add these to HTTP header ? I heard that we can send the User Name and Password using HTTP Basic authentication way. Is there a way to send other parameters also ?
Upvotes: 2
Views: 852
Reputation: 15446
You can make an with the Authorization header having the authentication details, such that further requests join the session and does not need authentication.
Here is how to add Authorization header:
Create the header value.
byte[] authBytes = Encoding.UTF8.GetBytes("user:password".ToCharArray());
String authHeaderValue = "Basic " + Convert.ToBase64String(authBytes);
Add the Authorization header with above value
Authorization: authHeaderValue
String webPage = "10.100.3.83:9764/example/servlets/servlet/…";;
URL url = new URL(webPage);
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
urlConnection.addRequestProperty("Name","andunslg");
//Username : andunslg
//Password : admin
byte[] authBytes = Encoding.UTF8.GetBytes("andunslg:admin".ToCharArray());
String authHeaderValue = "Basic " + Convert.ToBase64String(authBytes);
urlConnection.addRequestProperty("Authorization",authHeaderValue );
Upvotes: 2