Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 457
  • Last Modified:

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??!
0
snajalm
Asked:
snajalm
  • 8
  • 7
1 Solution
 
CEHJCommented:
Normally, that's no different from http:

http://www.exampledepot.com/egs/java.net/Auth.html
0
 
snajalmAuthor Commented:
But how do you setRequestProperty to construct your POST method?!
0
 
CEHJCommented:
That's a different question, but

http://www.exampledepot.com/egs/java.net/Post.html
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
snajalmAuthor Commented:
But there is nothing in this link...
0
 
CEHJCommented:
0
 
snajalmAuthor Commented:
But this link doesn't say anything about how to add "username" and "password" to the POST arguments before sending the request!  
0
 
CEHJCommented:
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
 
snajalmAuthor Commented:
so would it be something like,

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

0
 
CEHJCommented:
If the server expects them to arrive as headers, then yes
0
 
snajalmAuthor Commented:
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
 
CEHJCommented:
>>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
 
snajalmAuthor Commented:
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
 
CEHJCommented:
>>
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
 
snajalmAuthor Commented:
Thanks heaps for helping through this question!
0
 
CEHJCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now