Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Constructing a POST HTTPS Request (EMPHASIS ON USERNAME & PASSWORD)

Posted on 2011-09-29
15
Medium Priority
?
449 Views
Last Modified: 2012-05-12
How can I chuck in user credentials (username and password) in an HTTPS POST request in Java??!
0
Comment
Question by:snajalm
  • 8
  • 7
15 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 36814142
Normally, that's no different from http:

http://www.exampledepot.com/egs/java.net/Auth.html
0
 

Author Comment

by:snajalm
ID: 36814183
But how do you setRequestProperty to construct your POST method?!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36814336
That's a different question, but

http://www.exampledepot.com/egs/java.net/Post.html
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:snajalm
ID: 36814368
But there is nothing in this link...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36814426
0
 

Author Comment

by:snajalm
ID: 36814556
But this link doesn't say anything about how to add "username" and "password" to the POST arguments before sending the request!  
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36814605
Normally you don't do that - authentication is part of the protocol and the responsibility of the Authenticator. If in your case you do, then it would be no different from any other post parameters
0
 

Author Comment

by:snajalm
ID: 36815037
so would it be something like,

comm.setRequestProperty("user", userName);
comm.setRequestProperty("password", password);

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36815098
If the server expects them to arrive as headers, then yes
0
 

Author Comment

by:snajalm
ID: 36898372
Can you please let me know of all the possible ways of constructing a post request?  I just want to send the username and password as clear text through POST request!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36899089
>>I just want to send the username and password as clear text through POST request!

Well i already posted a link to an example of that. Just change

>>String data = "width=50&height=100";

to

String data = "username=foo&password=bar";
0
 

Author Comment

by:snajalm
ID: 36899238
I found a couple of cool links that help with making an HTTP POST request and make life a whole lot easier.

http://www.java2s.com/Code/Java/Apache-Common/HttppostmethodExample.htm

http://www.devx.com/Java/Article/17679/0/page/1
http://myjavatools.com/

Regards
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 36899269
>>
http://www.devx.com/Java/Article/17679/0/page/1
http://myjavatools.com/
>>

The above seem to be the same code. Personally i wouldn't use arbitrary code from the web, favouring instead mature APIs such as

>>http://www.java2s.com/Code/Java/Apache-Common/HttppostmethodExample.htm

Having said that, such an API is probably overkill for such a simple requirement (unless you're going to go on to do more complex things, such as cookie management) and you can get along just fine with the generic JRE code i posted without an extra  API
0
 

Author Closing Comment

by:snajalm
ID: 36928665
Thanks heaps for helping through this question!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36930292
No problem. As it happens, i'm working on a reusable https server at the moment and it makes stuff like key management quite simple (using Ant)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question