Link to home
Start Free TrialLog in
Avatar of snajalm
snajalm

asked on

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

How can I chuck in user credentials (username and password) in an HTTPS POST request in Java??!
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Normally, that's no different from http:

http://www.exampledepot.com/egs/java.net/Auth.html
Avatar of snajalm
snajalm

ASKER

But how do you setRequestProperty to construct your POST method?!
Avatar of snajalm

ASKER

But there is nothing in this link...
Avatar of snajalm

ASKER

But this link doesn't say anything about how to add "username" and "password" to the POST arguments before sending the request!  
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
Avatar of snajalm

ASKER

so would it be something like,

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

If the server expects them to arrive as headers, then yes
Avatar of snajalm

ASKER

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!
>>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";
Avatar of snajalm

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of snajalm

ASKER

Thanks heaps for helping through this question!
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)